I'm performing a POST call that returns some JSON. I have a function that works and uses HttpWebRequest, HttpWebResponse, and StreamReader to fire off the POST call and print back the returned JSON.
I'm now trying to create a new function that does the exact same thing but using an async call using HttpClient and HttpResponseMessage. Everything seems to work except when printing the json results. Instead of getting a deserialized json object with object fields and such, I get this:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Transfer-Encoding: chunked
Date: Fri, 16 Sep 2016 21:11:29 GMT
Server: Kestrel
Content-Type: text/plain; charset=utf-8
}
This seems to be information about the response, but not the actual JSON I was expecting. I'm completely new to web development and HttpClient - does anyone know what I'm doing wrong? Here's my HttpClient POST method:
public async static Task<HttpResponseMessage> POSTDataHttpContent(string jsonString, string webAddress)
{
using (HttpClient client = new HttpClient())
{
StringContent stringContent = new StringContent(jsonString);
HttpResponseMessage response = await client.PostAsync(
webAddress,
stringContent);
Console.WriteLine("response is: " + response);
return response;
}
}