[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.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
Result Message:
System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
解决
在请求前设置安全协议如下:
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Use SecurityProtocolType.Ssl3 if needed for compatibility reasons
参考资料
https://stackoverflow.com/a/2904963
[HTTPS] - 请求API失败(Could not create SSL/TLS secure channel)之解决的更多相关文章
- 偶尔遇到的“The request was aborted:Could not create SSL/TLS secure channel.”怎么解决?
项目中涉及到调用第三方的Https的WebService,我使用的是原始的HttpWebRequest. 代码中已经考虑到是Https,加上了SSL3协议,加上了委托调用.但偶尔还是会碰到 The r ...
- 请求被中止: 未能创建 SSL/TLS 安全通道,以及解决方法,即:Could not create SSL/TLS secure channel
C# 访问https请求被中止: 未能创建 SSL/TLS 安全通道(Could not create SSL/TLS secure channel) 以及 X509Certificate2 temp ...
- The request was aborted: Could not create SSL/TLS secure channel
一.背景: 公司底层服务CDN从Akamai迁移到阿里云之后, 使用该服务的一个应用报错如下: System.AggregateException: One or more errors occurr ...
- 微信退款时候报”请求被中止: 未能创建 SSL/TLS 安全通道“或”The request was aborted: Could not create SSL/TLS secure channel“的错误
如题,英文中文表述的是一个意思 退款测试在我本机测试一切都是正常的,但是发布到了服务器就报这样的一个错啦 但是无论百度或者google或者bing,你能够搜索到的结果都很类似,综合起来就是加这样一些代 ...
- 【转】微信退款时候报”请求被中止: 未能创建 SSL/TLS 安全通道“或”The request was aborted: Could not create SSL/TLS secure channel“的错误
退款测试在我本机测试一切都是正常的,但是发布到了服务器就报这样的一个错啦 但是无论百度或者google或者bing,你能够搜索到的结果都很类似,综合起来就是加这样一些代码,如下 ServicePoin ...
- Could not create SSL/TLS secure channel.
解决办法: ServicePointManager.Expect100Continue = true;ServicePointManager.SecurityProtocol = SecurityPr ...
- visual studio Web发布至 IIS WebDeploy出错(未能创建SSL/TLS安全通道)Could not create SSL/TLS secure channel
问题发生的原因是VS 15.9尝试使用系统默认值进行TLS握手,但是要在VS内的某处设置为TLS1.2. 此问题的解决方法是在部署项目的IIS服务器上启用TLS 1.2.例如,请按照此文章中的说明操作
- Web Server 使用WebClient 发送https请求 The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel
使用WebClient 发送https请求 使用WebClient发送请求时,并且是以https协议: WebClient webClient = new WebClient(); string re ...
- https请求时出错:Could not establish trust relationship for the SSL/TLS secure channel
当我在用NET命名空间下获取URL的时候,提示如下错误: The underlying connection was closed: Could not establish trust relatio ...
随机推荐
- Linux系统配置静态ip
一.工具/原料 redhat6.2 二.步骤 1."网络适配器"选择"桥接模式" 右键虚拟机,选择"设置"->"网络适配器& ...
- [Linux] RTC 读写指令及测试程序
CPU:RK3288 系统:Linux IC:hym8563 在 Linux 系统中,指令 date 和 hwclock 都可以读写时间 date:读写系统时间,写时间需要管理员权限 hwclock: ...
- 腾讯云CENTOS7安装MSSQL2017
腾讯云CENTOS7安装MSSQL2017 mkdir -p /opt/sqlserver2017cd /opt/sqlserver2017/ 下载离线包:wget https://packages. ...
- Java IO系统--RandomAccessFile
RandomAccessFile 实现了DataOutput接口和DataInput接口.父类是Object,不继承任何的InputStream和OutStram. public class Rand ...
- 小程序 跳转web-view 点击左上角返回需要点击2次才能返回
小程序 跳转web-view 点击左上角返回需要点击2次才能返回 再html页面引入js即可解决 <script type="text/javascript" src=& ...
- nrm -- 一键切换npm源
0. 背景 先描述一下没有nrm时我们是怎样使用npm源的 查看npm源地址,终端中输入 npm config list 可以看到npm源 metrics-registry = "https ...
- Shell脚本自动重启Java服务
话不多说直接上代码: cd /home/javaProduct/if [ -d '/home/javaProduct/lib_new/' ]; thenecho 'Has New Lib!'echo ...
- windows下安装node【转】
windows下安装node报错2503.2502 windows下命令行安装,首先使用管理员权限获取cmd msiexec /package node-v10.16.0-x64.msi 根据提示一步 ...
- 【Python】使用POST方式抓取有道翻译结果
1.安装requests库 2.打开有道翻译,按下F12,进入开发者模式,输入我爱青青,点击Network,再点击XHR 3.撰写爬虫 import requestsimport json # 使用有 ...
- 【插件式框架探索系列】使用多UI线程提升性能
了解WPF线程模型的都知道,UI线程负责呈现和管理UI,而UI元素(派生自 DispatcherObject)只能由创建该元素的线程来访问,这就导致了一些耗时的UI操作将影 响到整个应用程序性能,未响 ...