System.Net.WebException: 基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。 ---> System.Security.Authentication.Authe
System.Net.WebException: 基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。 —> System.Security.Authentication.AuthenticationException: 根据验证过程,远程证书无效。
解决方法:
public static class Util{//由于api的特殊性,需要在我们发出请求前,解决未能建立安全通信通道问题,为这次连接设置安全认证public static void SetCertificatePolicy(){ServicePointManager.ServerCertificateValidationCallback+= RemoteCertificateValidate;}private static bool RemoteCertificateValidate(object sender, X509Certificate cert,X509Chain chain, SslPolicyErrors error){// trust any certificate!!!System.Console.WriteLine("Warning, trust any certificate");return true;}}
写一个utils类,当你在
class HttpUitls{public static class Util{//由于api的特殊性,需要在我们发出请求前,解决未能建立安全通信通道问题,为这次连接设置安全认证public static void SetCertificatePolicy(){ServicePointManager.ServerCertificateValidationCallback+= RemoteCertificateValidate;}private static bool RemoteCertificateValidate(object sender, X509Certificate cert,X509Chain chain, SslPolicyErrors error){// trust any certificate!!!System.Console.WriteLine("Warning, trust any certificate");return true;}}public static string Get(string Url){Util.SetCertificatePolicy();HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);request.Proxy = null;request.KeepAlive = false;request.Method = "GET";request.ContentType = "application/json; charset=UTF-8";request.AutomaticDecompression = DecompressionMethods.GZip;//get请求,返回json文件HttpWebResponse response = (HttpWebResponse)request.GetResponse();Stream myResponseStream = response.GetResponseStream();StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);string retString = myStreamReader.ReadToEnd();myStreamReader.Close();myResponseStream.Close();if (response != null){response.Close();}if (request != null){request.Abort();}return retString;}}
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
上面这个代码前添加这个方法
Util.SetCertificatePolicy();
为本次连接设置证书。
System.Net.WebException: 基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。 ---> System.Security.Authentication.Authe相关推荐
- C#Post接口报错信息:基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系--安全证书问题 解决方法
目录 一.说明: 二.错误信息: 三.解决方法 1.引用命名空间: 2.添加接收方法(CheckValidationResult): 3.post方法里面增加调用:CheckValidationRes ...
- 解决Error基础连接已经关闭: 未能为SSL/TLS 安全通道建立信任关系
今天写程序的时候调用到一个第三方的DLL文件,本机调试一切都正常,但是程序不是到服务器以后一直提示一个BUG:"基础连接已经关闭: 未能为SSL/TLS 安全通道建立信任关系". ...
- C#运行出现:基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。
英文:The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secu ...
- C#调用webapi HTTPS报错:基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系--安全证书问题
1.首先加入命名空间: using System.Net.Security; using System.Security.Authentication; using System.Security.C ...
- c# System.Net.WebException: 基础连接已经关闭: 发送时发生错误。
本文介绍了C#System.Net.WebException:基础连接已关闭:发送时发生意外错误 -> System.IO.IOException: 无法从传输连接中读取数据: 远程主机强迫关闭 ...
- c# OpenRead 请求被中止: 未能创建 SSL/TLS 安全通道。
以前一直用的一套看指定网页的源代码的,今天突然报了个错, "System.Net.WebException"类型的未经处理的异常在 System.dll 中发生 其他信息: 请求被 ...
- Https未能创建 SSL/TLS 安全通道。Could not create SSL/TLS secure channel解决方案
描述:请求被中止: 未能创建 SSL/TLS 安全通道.Could not create SSL/TLS secure channel. 产生平台:Windows Server 2012,Window ...
- PAYPAL 支付,sandbox测试的时候遇到异常:请求被中止: 未能创建 SSL/TLS 安全通道,以及解决方法。...
场景描述: 我公司的网站之前就已经开发好了下单支持paypal支付,当然,这个是其他同事开发的.前段时间,主管让我在另一个场景开发支持使用paypal支付,当时花了些时间看看关于paypal代码,然后 ...
- IIS7下 【请求被中止: 未能创建 SSL/TLS 安全通道 】 解决方法
IIS7下 [请求被中止: 未能创建 SSL/TLS 安全通道 ] 解决方法 参考文章: (1)IIS7下 [请求被中止: 未能创建 SSL/TLS 安全通道 ] 解决方法 (2)https://ww ...
- PAYPAL 支付,sandbox测试的时候遇到异常:请求被中止: 未能创建 SSL/TLS 安全通道,以及解决方法。
PAYPAL 支付,sandbox测试的时候遇到异常:请求被中止: 未能创建 SSL/TLS 安全通道,以及解决方法. 参考文章: (1)PAYPAL 支付,sandbox测试的时候遇到异常:请求被中 ...
最新文章
- centos6上以二进制方式安装mariadb5.5
- 实战药物分子筛选之一_初探
- python: ImportError:DLL load failed 解决方法。
- 数据结构 - 有两个链表,第一个升序,第二个降序,合并为一个升序链表(C++)
- 基于实时深度学习的推荐系统架构设计和技术演进
- WIN7+wampserver2.4+zend stadio10.6.1配置Xdebug
- android 仿微信侧滑删除SwipeListView实例
- 最短路径 | 1087 三重标尺+记录最短路径条数
- 2060显卡驱动最新版本_聊一款现阶段性价比爆炸的显卡——铭瑄RTX2070 SUPER 电竞之心 OC...
- 51单片机之逻辑运算指令ANL、ORL、XRL等
- 杨超越杯编程大赛上热搜:不懂技术真不敢追星
- 圣迭戈与哥大电子计算机,加州大学圣迭戈分校
- 第7章 分析恶意的windows程序
- 微型计算机音节,二年级微机下册教案
- Coda 2.5 发布,Mac 编辑器软件
- C语言:编程计算π的近似值(直到最后一项的绝对值小于10-5为止),要求保留小数点后10位。
- 最新版抖音(20200624)去水印原理及源码,简单的原理与面临的挑战
- TEC控温模块电路分析
- 用友ERP/NC--张丹(转自用友网站)
- Android开发资源(一)