异常处理-System.IO.IOException: 由于远程方已关闭传输流,身份验证失败

时间:2019-10-20 14:43:00   收藏:0   阅读:494

 

在.NET 3.5下创建的WinForm程序调用Core 3.0 Web API时出现“IOException: 由于远程方已关闭传输流,身份验证失败”错误

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
HttpWebResponse myResponse
= (HttpWebResponse)myRequest.GetResponse();//IOException: 由于远程方已关闭传输流,身份验证失败。

错误详细:

技术分享图片
System.Net.WebException
HResult=0x80131509
Message=基础连接已经关闭: 发送时发生错误。
Source=<无法计算异常源>
StackTrace:
<无法计算异常堆栈跟踪>

内部异常 1:
IOException: 由于远程方已关闭传输流,身份验证失败。
View Code

解决办法:

技术分享图片
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
//4.5版本以上可使用:ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
View Code

参考:

https://codeday.me/bug/20180824/224009.html

https://www.cnblogs.com/merray/p/6364863.html

原文:https://www.cnblogs.com/yangwang365/p/11707253.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!