C#模擬Http請求時出現 基礎連接已經關閉 未能為 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;