Reputation: 2287
I have a problem. I migrate from WebRequest to HttpClient. In WebRequest i simple implement:
var webRequest = (HttpWebRequest)WebRequest.Create("http://111.111.111.111:8080/method");
webRequest.Host = "mysite:8080.com";
And http requests works fine.
Then i replace WebRequest on HttpClient, and faced with the problem.
var client = new HttpClient();
client.DefaultRequestHeaders.Host = "mysite:8080.com";
var result = await client.GetAsync("http://111.111.111.111:8080/method", cancellationToken).ConfigureAwait(false); // rise 404 error
GetAsync rise 404 in this case. HttpClient can't send requests on specified ip's?
Upvotes: 1
Views: 7504
Reputation: 10528
This might be old, but to those who can bump in this error, here you can use this method :
static async void getHttpClient()
{
string mUrl = "http://192.168.1.111/method";
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(mURL))
using (HttpContent content = response.Content)
{
string result = await content.ReadAsStringAsync();
if (result != null)
{
Console.WriteLine(result);
} else
{
//
// ERROR
//
}
}
}
happy codings
Upvotes: 2