I am building REST Client (c#) using windows form application in VS2017. I have been able to successfully GET and POST requests from the server using the HttpClient.PostAsJsonAsync() and ReadAsync() methods. I am trying to POST some data to the server and upon a successful POST, the server responds with a unique string like "1c77ad2e-54e0-4187-aa9d-9a55286b1f7a"
I get a successful response code (200 - OK) for the POST. However, I am not sure where to check for the resulting string. I have checked the contents of HttpResponseMessage.Content
static async Task<HttpStatusCode> PostBurstData(string path, BurstRequest
burstRequest)
{
HttpResponseMessage response = await client.PostAsJsonAsync(path, burstRequest);
response.EnsureSuccessStatusCode();
Console.WriteLine(response.Content.ToString());
// return response
return response.StatusCode;
}
The data sent to this function call is as follows:
BurstRequest request = new BurstRequest();
request.NodeSerialNumbers = SubSerialList;
request.StartTime = ((DateTimeOffset)dateTimePicker1.Value).ToUnixTimeMilliseconds();
HttpStatusCode statusCode = new HttpStatusCode();
statusCode = await PostBurstData(post_burst_url, request);
Where should I search for the string the server responds for a successful POST? Should the content be read using ReadAsync()?
if (response.IsSuccessStatusCode)
{
var data = await response.Content.ReadAsAsync();
}