B
BigDon49
Guest
I've been trying to figure out how to use the HTTPClient class in my C# efforts. I've found several examples on youtube that all use similar code and I see it all work for the creators of those videos. As best I can tell, my code is exactly the same as the code in one of those videos. But yet even though it worked in the video, every time I run it, it crashes.
I'm at a complete loss as to why it fails for me but worked in the video.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
//I placed a breakpoint at this line and stepped through the rest of the code.........
GetRequest("Google");
}
async static void GetRequest(String URL)
{
using (HttpClient client = new HttpClient())
{
// As soon as I try to step over (or even into) this next line, it crashes.
using (HttpResponseMessage response = await client.GetAsync(URL))
{
using (HttpContent content = response.Content)
{
string data = await content.ReadAsStringAsync();
Console.WriteLine(data);
}
}
}
Console.ReadKey();
}
}
}
Don
Continue reading...
I'm at a complete loss as to why it fails for me but worked in the video.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
//I placed a breakpoint at this line and stepped through the rest of the code.........
GetRequest("Google");
}
async static void GetRequest(String URL)
{
using (HttpClient client = new HttpClient())
{
// As soon as I try to step over (or even into) this next line, it crashes.
using (HttpResponseMessage response = await client.GetAsync(URL))
{
using (HttpContent content = response.Content)
{
string data = await content.ReadAsStringAsync();
Console.WriteLine(data);
}
}
}
Console.ReadKey();
}
}
}
Don
Continue reading...