https调用出现【基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系】错误

是写入流失败了,报【基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系】错误

先加入命名空间:

using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;

再重载CheckValidationResult方法,返回true

public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
    {  // 总是接受  
        return true;
    }

然后在HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);前面加上如下一行代码:
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);

加上了之后发现立即就可以访问了,然而总线还在想替换证书,诶,随他去吧,双方都严谨点问题才会少出点!

 

posted @ 2017-10-11 15:16  $JackChen  阅读(898)  评论(0编辑  收藏  举报