[英]System.Net.WebException not intercepted on Windows Phone 8
[英]Post async throw System.Net.WebException on Windows 7 WPF client
从 WPF 控件中托管的 httpclient 向 azure 服务器进行查询,azure 服务器将结果发送回 WPF 控件。 在 Windows 7 操作系统上,调用 postasync 时会引发异常。 请帮助我如何解决以下异常。
注意:这在 Windows 10 客户端机器上工作正常
var httpContent = new StringContent(value, Encoding.UTF8, "application/json");
var queryUri = new Uri(httpClient.BaseAddress, "content/resultvalue");
try {
var response = await httpClient.PostAsync(queryUri, httpContent);
response.EnsureSuccessStatusCode();
var resultJson = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<Result>(resultJson);
} catch (Exception e) {
//report the exception to the user
}
异常消息:WebException:基础连接已关闭:发送时发生意外错误。 IOException : 无法从传输连接读取数据:远程主机强行关闭了现有连接。 SocketException : 现有连接被远程主机强行关闭
类型:System.Net.WebException,System,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089 消息:基础连接已关闭:发送时发生意外错误。 源:系统状态:SendFailure 响应:目标站点:System.IO.Stream EndGetRequestStream(System.IAsyncResult, System.Net.TransportContext ByRef) 堆栈跟踪:在 System.Net 的 System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) 在 System.Net .Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) 内部异常 --------------- 类型:System.IO.IOException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089消息:无法从传输连接读取数据:远程主机强行关闭了现有连接。 来源:System TargetSite:Void EndWrite(System.IAsyncResult) 堆栈跟踪:在 System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) 在 System.Net.PooledStream.EndWrite(IAsyncResult asyncResult) 在 System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) ) 内部异常 --------------- 类型:System.Net.Sockets.SocketException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 消息:现有连接被强行被远程主机关闭 Source : System ErrorCode : 10054 SocketErrorCode: ConnectionReset NativeErrorCode: 10054 TargetSite : Int32 EndReceive(System.IAsyncResult) Stack Trace : at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets。 NetworkStream.EndRead(IAsyncResult asyncResult)
这可能是防火墙问题或 SecurityProtocol 版本不匹配。
尝试这个:
System.Net.ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12;
或者由于 Azure TLS 默认版本是 1.2,您可以尝试将其更改为 1.0 并查看是否有任何区别(在SSL Settings
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.