0

I'm having some issues with making a POST call using C#'s HttpClient's PostAsync giving me a NullReferenceException. The method is below.

public String MakeSyncPostRequest(String data)
{
Uri url = new Uri(HostName);
var response = Client.PostAsync(url, new StringContent(data)).Result;
String answer = response.Content.ReadAsStringAsync().Result;
return answer;
}

I've gone through the method several times, and none of the variables in there are null, so I'm not sure what exactly the problem is. I'm kind of new working with asynchronous methods, so maybe I'm just missing something. This is part of a .NET standard library I'm writing that is being tested in a console application. Has anyone else experienced this problem? And yes, I have a similar method that is async I'm having the same issue with it. Thanks for any help.

user2850818
  • 319
  • 3
  • 15

0 Answers0