0

我正在使用 HttpClient 在我的 Windows 8 应用程序中从服务器发送和接收数据。

下面是我的代码:

HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
handler.AutomaticDecompression = DecompressionMethods.GZip;

HttpClient httpClient = new HttpClient(handler);
httpClient.Timeout = TimeSpan.FromSeconds(30);
httpClient.DefaultRequestHeaders.ExpectContinue = false;

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, URL);

request.Content = new StreamContent(new System.IO.MemoryStream(_postDataInBytes));
request.Content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

HttpResponseMessage response = await httpClient.SendAsync(request);

现在的问题是我在 SendAsync() 函数中遇到异常。例外是“底层连接已关闭:接收时发生意外错误”。这是随机发生的。谁能告诉我这里有什么问题?

4

0 回答 0