C#模擬Http請求時出現 基礎連接已經關閉 未能爲 SSLTLS 安全通道建立信任關係

 

https://blog.csdn.net/soarheaven/article/details/79036333

 

https://www.cnblogs.com/ianunspace/p/5508179.html

//解決方法:

//引入命名空間:
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;


//定義方法:

private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
    //爲了通過證書驗證,總是返回true
    return true;
}


//調用方法一:

//在構造函數中調用:

static WxRequest()
{
    // 獲取驗證證書的回調函數
    ServicePointManager.ServerCertificateValidationCallback+=RemoteCertificateValidate;
}

//方法二:

//在WebRequest請求之前調用:

ServicePointManager.ServerCertificateValidationCallback+=RemoteCertificateValidate;

 

 

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