基礎連接已經關閉: 發送時發生錯誤

System.Net.WebException: 基礎連接已經關閉: 發送時發生錯誤。 

目標積極拒絕。

在使用下面代碼時,發生上面的問題。

oHttp_Web_Req.GetResponse();

查找了很多,都不對,只有以下這種方案是最靠譜的。

解決辦法是這樣的:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12|SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.CheckCertificateRevocationList = false;
ServicePointManager.DefaultConnectionLimit = 512;
ServicePointManager.Expect100Continue = false;

HttpWebRequest oHttp_Web_Req = (HttpWebRequest)WebRequest.Create("https://XXXX.com");

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章