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;

 

 

展开阅读全文

没有更多推荐了,返回首页