在.NET 3.5下建立的WinForm程序调用Core 3.0 Web API时出现“IOException: 因为远程方已关闭传输流,身份验证失败”错误html
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();//IOException: 因为远程方已关闭传输流,身份验证失败。
错误详细:ide


System.Net.WebException HResult=0x80131509 Message=基础链接已经关闭: 发送时发生错误。 Source=<没法计算异常源> StackTrace: <没法计算异常堆栈跟踪> 内部异常 1: IOException: 因为远程方已关闭传输流,身份验证失败。
解决办法:spa


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();
参考:code