我以这种方式将字符串发布到 Web 服务器:
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);
}
}
但response.EnsureSuccessStatusCode();
抛出一个HttpRequestException
. 当我e.Message
对异常进行处理时,它说:Response status code does not indicate success: 500 (Internal Server Error).
。
我做错了什么,我得到了那个错误?我该如何纠正?