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;

 

posted @ 2016-05-19 11:54  落一叶而知秋  阅读(4131)  评论(0编辑  收藏  举报