https请求时出错:Could not establish trust relationship for the SSL/TLS secure channel
2015-09-14 13:10
861 查看
当我在用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; } }View Code
然后,你要在调用请求HTTPS时,先调用这个方法: Util.SetCertificatePolicy();
相关文章推荐
- hdu 5442 (ACM-ICPC2015长春网络赛F题)
- Android 网络连接:Volley(齐射)之ImageRequest与NetworkImageView网络图片下载
- 2015年长春区域网络赛 hdu 5441 Travel【并查集】
- HDU 5441 Travel (2015年长春赛区网络赛E题)
- Android 网络连接:Volley(齐射)之简单使用
- Asynctask异步加载使用方法
- HDU 5441 Travel (2015ACM/iCPC长春网络赛E )
- 利用HTTP-only Cookie缓解XSS之痛
- 网络连接之HttpClient,Volley,xUtils
- 网络排错
- http方法总结
- Android之访问网络,使用HttpURLConnection还是HttpClient?
- 一些网络用语
- hdu5438(2015长春赛区网络赛1002)拓扑序+DFS
- 验证视图状态 MAC 失败。如果此应用程序由网络场或群集承载,请确保<machineKey>
- AFNetWorking与Https
- hdu 5439 Aggregated Counting 2015长春网络赛 分块 二分 预处理
- hdu5441(2015长春网络赛E题)
- Linux学习笔记----虚拟机CentOS访问网络的设置方法
- AFNetworking与https