異常處理-System.IO.IOException: 由於遠程方已關閉傳輸流,身份驗證失敗


 

在.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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM