I am posting a string to a web server this way:
private async Task makeRequest(string url, string postData)
{
HttpClient client = null;
HttpResponseMessage response = null;
try
{
client = new HttpClient();
response = await client.PostAsync(url, new StringContent(postData));
response.EnsureSuccessStatusCode();
Debug.WriteLine(response.StatusCode + " " + response.ReasonPhrase);
}
catch (HttpRequestException e)
{
Debug.WriteLine(e.Message);
}
}
But response.EnsureSuccessStatusCode();
throws a HttpRequestException
. When I did a e.Message
on the exception, it says : Response status code does not indicate success: 500 (Internal Server Error).
.
What am I doing wrong that I get that error? And how do I correct it?