I am creating a NuGet package to retrieve images from an online API. I am using .NetStandard 1.4 and using System.Net.Http version 4.3.2. Every time I call the Login method to get a token to access the api, the http call never returns and just hangs till the task cancelation exception happens due to timing out. I have tried multiple solutions I have found online such as making sure there are no .Result or .Wait() before the async call and there are none in my test. I have also tried using an incorrect url and the call still hangs and doesn't return saying the url doesn't exist.
I have posted the main http call below. Any help on why this is hanging would be very much appreciated.
HttpRequestMessage requestMessage = new HttpRequestMessage();
requestMessage.RequestUri = new Uri($"{BaseUrl}/login");
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(HttpContentType.JSON));
requestMessage.Method = HttpMethod.Post;
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(values), Encoding.UTF8, HttpContentType.JSON);
using (HttpClient httpClient = new HttpClient())
{
using (HttpResponseMessage response = await httpClient.SendAsync(requestMessage))
{
if (response.IsSuccessStatusCode == true)
{
// Do work
}
}
}
The BaseUrl value and the path for the website is correct and I have checked that. Also I have used the same link and all the information I need to send in Postman in order to verify I am using the correct information.
I have tried to test this using MSTest, a console project, and a WPF project using a button and click event to fire off this method. Every method hangs and never gets passed the
using (HttpResponseMessage ...