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

//解決方法:

//引入命名空間:
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;
相關文章
相關標籤/搜索