基础连接已经关闭: 发送时发生错误

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");

 

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