unathi guma

unathi guma

  • NA
  • 40
  • 9.8k

I want to return the return the response body of POST

Mar 19 2019 7:52 AM
Good day
 
I want to return a response body but my code is only returning a Status message. Please help
 
static async Task<string> PostURI(Uri u, HttpContent c)
{
var response = string.Empty;
using (var client = new HttpClient())
{
HttpResponseMessage result = await client.PostAsync(u, c);
if (result.IsSuccessStatusCode)
{
response = result.StatusCode.ToString();
}
}
return response;
}
 
 
Uri u = new Uri("URL");
var payload = results;
HttpContent c = new StringContent(payload, Encoding.UTF8, "application/json");
var t = Task.Run(() => PostURI(u, c));
t.Wait();
Console.WriteLine(t.Result);
Console.ReadLine();
 

Answers (5)