https请求时出错:Could not establish trust relationship for the SSL/TLS secure channel

当我在用NET命名空间下获取URL的时候,提示如下错误:

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

使用传输安全模式,证书建立SSL,宿主端口证书配置完毕,但是客户调用服务出错。

Could not establish trust relationship for the SSL/TLS secure channel with authority ‘computer:9001‘.
不能和授权计算机为 SSL/TLS 安全通道建立信任关系

【1】问题分析:
       Could not establish trust relationship for the SSL/TLS secure channel with authority ‘computer:9001‘.
不能和授权计算机为 SSL/TLS 安全通道建立信任关系.
       实际原因和证书有很大关系,这里证书是跟证书颁发机构信任的证书,在客户端和服务端建立安全会话的时候,无法信任此证书。
    另外一个可能的原因是你其他域里也使用此一个证,这个也有可能导致错误。
【2】解决办法:

定义一个类,来对远程X.509证书的验证,进行处理,返回为true.我们要自己定义一个类,然后在客户单调用WCF服务之前,执行一次即可。

代码如下:

 public static class Util
    {
        /// <summary>
        /// Sets the cert policy.
        /// </summary>
        public static void SetCertificatePolicy()
        {
            ServicePointManager.ServerCertificateValidationCallback
                      += RemoteCertificateValidate;
        }

        /// <summary>
        /// Remotes the certificate validate.
        /// </summary>
        private static bool RemoteCertificateValidate(
           object sender, X509Certificate cert,
             X509Chain chain, SslPolicyErrors error)
        {
            // trust any certificate!!!
            System.Console.WriteLine("Warning, trust any certificate");
            return true;
        }
    }

然后,你要在调用请求HTTPS时,先调用这个方法: Util.SetCertificatePolicy();

时间: 2024-07-30 19:19:23

https请求时出错:Could not establish trust relationship for the SSL/TLS secure channel的相关文章

Could not establish trust relationship for the SSL/TLS secure channel 问题解决方法

最近在写一个跟第三方对接的数据同步服务,在本地都没有问题,今天放到生产环境测试报错: System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. 对方用的是https,看错误是证书问题,查了一些资料,貌似说这个问题的比较少,所以在此总结一下,以防以后用到. public string Get

微信请求数据错误The request was aborted: Could not create SSL/TLS secure channel.

今天在后台向微信服务器请求JSON数据时,返回了错误:The request was aborted: Could not create SSL/TLS secure channel. 查了一下,原来去年SSL协议曝出高危漏洞后,微信公众平台关闭了SSLv2.SSLv3版本支持,请求数据时应该使用TLS或更高版本. //在请求之前修改安全协议为TLS ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; 至于SSL和TL

[HTTPS] - 请求API失败(Could not create SSL/TLS secure channel)之解决

背景 在单元测试中请求 HTTPS API 失败. 异常 Result StackTrace:  at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Pr

https网站访问第三方https网站时候报错: The request was aborted:Could not create SSL/TLS secure channel.

https网站访问第三方https网站时候报错: The request was aborted:Could not create SSL/TLS secure channel. 解决办法: if(Url.StartsWith("https",StringComparison.OrdinalIgnoreCase))//https请求 { ServicePointManager.Expect100Continue = true; //如果是4.5以上版本可以直接使用 //ServiceP

微信退款时候报”请求被中止: 未能创建 SSL/TLS 安全通道“或”The request was aborted: Could not create SSL/TLS secure channel“的错误

如题,英文中文表述的是一个意思 退款测试在我本机测试一切都是正常的,但是发布到了服务器就报这样的一个错啦 但是无论百度或者google或者bing,你能够搜索到的结果都很类似,综合起来就是加这样一些代码,如下 ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | Secu

Global.asax.cs 为 /.aspx 执行子请求时出错。 Server.Transfer

x 后台代码 Global.asax.cs protected void Application_Error(object sender, EventArgs e){Server.Transfer("/Error.aspx", true);} 跳转到错误页面的时候,直接报错:"为 /Error.aspx 执行子请求时出错" 我的解决方案 所以问题就是. Global.asax.cs中的Application_Error执行"Server.Transfer(

解决 ASP.NET Chart 控件出错 为 ChartImg.axd 执行子请求时出错

    今天在做一个关于MVC的MSChart时,本以为很简单的一个东西,后面把数据什么的都绑定好后,满以为OK了,一运行就报错“ ASP.NET Chart 控件出错 为 ChartImg.axd 执行子请求时出错 ”,纠结~~后面网上搜了一下这方面的解决方案,然后结合自己的,最后做了一个小的总结: 一.在vs2008中,你需要按照如下的步骤进行配置: 1.<pages controlRenderingCompatibilityVersion="3.5" enableEvent

Fiddler捕获https请求时勾选了Decrypt HTTPS traffic还是获取不到证书的问题(转)

问题  (点击Actions中的Trust Root Certificate和Export Root Certificate to Desktop也会出错)如图所示勾选了Decrypt HTTPS traffic点击ok后,打开浏览器输入网址http://localhost:8888,进入如下界面: 点击FiddlerRoot certificate链接后提示找不到证书:  解决办法 进入Fiddler目录,我这默认安装路径是C:\Users\Administrator.QH-20150808S

解决Asp.net中的Chart控件运行出现错误提示“ ChartImg.axd 执行子请求时出错”

首先经过错误提示看出需要保存路径之类的,所以猜测是不是配置文件出错了.看了一下配置文件只有连接字符串的配置.后来重新把vs2010关了重新打开,又新建了一个页面,重新添加空间然后运行使用.然后再看配置文件,发现多了许多东西.具体没有配置的东西如下: <?xml version="1.0"?> <!-- 有关如何配置 ASP.NET 应用程序的详细消息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --> &l