首页 > Web开发 > 详细

post请求远程url 报错“基础连接已经关闭...Authentication.AuthenticationException...远程证书无效”解决方案

时间:2015-02-16 16:44:26      阅读:702      评论:0      收藏:0      [点我收藏+]

当我们有时用代码编写post请求url远程地址会报“基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。 ---> System.Security.Authentication.AuthenticationException: 根据验证过程,远程证书无效。”这个异常,是因为远程url使用的域名 没有购买证书,所以用以下方式来解决:

ps:在create url之前 设定“获取或设置用于验证服务器证书的回调”永远为true 即可,具体如下

post请求一定需要:System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);

在这句代码前加上: ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;即可

RemoteCertificateValidate事件代码如下:

private static bool RemoteCertificateValidate(object sender, X509Certificate cert,X509Chain chain, SslPolicyErrors error)
        {
            //为了通过证书验证,总是返回true
            return true;
        }

搞定

 

post请求远程url 报错“基础连接已经关闭...Authentication.AuthenticationException...远程证书无效”解决方案

原文:http://www.cnblogs.com/yonguibe/p/4294234.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!