[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://www.cnblogs.com/jinzesudawei/p/9328211.html

时间: 2024-10-15 18:11:58

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

偶尔遇到的“The request was aborted:Could not create SSL/TLS secure channel.”怎么解决?

if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))///https请求 {     ServicePointManager.Expect100Continue = true;     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; //SSL3协议替换成TLS协议     ServicePointManager.ServerCe

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

微信请求数据错误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

微信退款时候报”请求被中止: 未能创建 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

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 wi

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

关于解决 请求被中止:无法建立SSL / TLS安全通道

我使用HttpWebRequest访问其他网站时,出现"请求被中止:无法建立 SSL / TLS安全通道"错误,于是goog和百度了一番,提供的答案基本 是:ServicePointManager.ServerCertificateValidationCallback写委托 public ResponseModel GetHtml(string url) { ServicePointManager.ServerCertificateValidationCallback = Valida

(转) HTTP & HTTPS网络协议重点总结(基于SSL/TLS的握手、TCP/IP协议基础、加密学)

HTTP & HTTPS网络协议重点总结(基于SSL/TLS的握手.TCP/IP协议基础.加密学) 原文:http://blog.csdn.net/itermeng/article/details/78517364 原文地址:https://www.cnblogs.com/liujiacai/p/8325931.html

SSL/TLS(Secure Sockets Layer / Transport Layer Security)

# 协议概述 缩写 名称 默认端口 安全策略 描述 HTTP Hyper Text Transfer Protocol(超文本传输协议) TCP80 HTTP 协议是明文的,传输内容会被嗅探和篡改. 客户端浏览器或其他程序与Web服务器之间的应用层通信协议 SSL/TLS Secure Sockets Layer(安全套接层)Transport Layer Security(传输层安全) TCP443 1)认证用户和服务器,确保数据发送到正确的客户机和服务器: 2)加密数据以防止数据中途被窃取: