Curl 请求被中止 未 能 创建SSL/TLS 安全通道

4 个解决办法,我用的第四个方法就解决了, 注册表手动添加的 重启后不管用,第四个方法 直接用程序改一下方便

首先得保证服务器是否支持 tls1.2 去注册表里查或者百度怎么查,基本大多数都用的是1.2  

Curl 请求被中止 未 能 创建SSL/TLS 安全通道

Curl 请求被中止 未 能 创建SSL/TLS 安全通道

1.   

代码前加这个 

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

或者 ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

或者

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3

| SecurityProtocolType.Tls

| (SecurityProtocolType)0x300 //Tls11

| (SecurityProtocolType)0xC00; //Tls12

2. 复制下面注册表代码导入到注册表。新建txt,将后缀txt改为reg(注册表项),导入

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp]
"DefaultSecureProtocols"=dword:00000800

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp]
"DefaultSecureProtocols"=dword:00000800

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001

3. 升级 到 fromwork4.6 版本

4.

​​https://www.nartac.com/Products/IISCrypto/Download​​

去下载这个软件 打开软件后 都选上确定 重启就好了

Curl 请求被中止 未 能 创建SSL/TLS 安全通道

  • 收藏
  • 评论
  • 举报

相关文章

请求被中止: 未能创建 SSL/TLS 安全通道

英文搜索关键词 : the request was aborted could not create ssl/tls (net 4.6)

statckoverflow 上面大多答案如下:

ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

也有用如下的(强烈不建议使用)

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

原因:

  1. Tls1.0 由于安全原因,大部分https服务端已经不再建议支持。

  2. .Net 4.5及之前的版本,不支持Tls1.2 ,SecurityProtocolType这个枚举中没有Tls12这个项

  3. Windows Server 2012 R2中,安装了.Net 4.6.x或4.7.x后,虽然系统支持,.Net也支持,但是默认的协商协议列表不包含Tls1.2

解决方案(PowerShell脚本):

查看当前系统中默认启用的协商协议列表

[Net.ServicePointManager]::SecurityProtocol

打印出来的结果应该是不包含Tls12 的,我实测的Win10 1603以及Windows Server 2012 R2显示均为如下:

Ssl3, Tls

继续执行如下代码,修改设置:

针对64位.Net:

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

针对32位.Net:

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

关闭PowerShell窗口,打开一个新的PowerShell窗口,执行以下代码

[Net.ServicePointManager]::SecurityProtocol

结果如下:

Tls, Tls11, Tls12, Tls13

重启之前受影响的.Net应用程序即可生效

.Net <4.5.x 参考链接 https://stackoverflow.com/questions/27953681/changing-security-protocol-per-request-httpclient

.Net 4.6.x参考链接 https://trailheadtechnology.com/solving-could-not-create-ssl-tls-secure-channel-error-in-net-4-6-x/

官方资料:https://docs.microsoft.com/en-us/security/solving-tls1-problem


ps: 然后以上处理并没有解决我的问题。。。o(╥﹏╥)o

在生产机器上多次curl测试,发现偶尔才会出现,并非必现。于是我很机智的,在出现此异常时重试三次。最终搞定了!

推荐阅读更多精彩内容

  • 在创建请求地址的前面加了这句代码就可以了: System.Net.ServicePointManager.Secu...

  • 前言 HTTPS是什么相信大家都知道,如果你不知道。。。请关闭此文!!!HTTP的数据是明文传输的,没有安全性可言...

  • 目录 一、https概述 1. 什么是HTTP? 2. 什么是HTTPS? 3. SSL/TLS...

    出走的流星阅读 11,652评论 4赞 26

  • 一:老师,您好。问这个问题,我是克服了很大的心理障碍。我们家经济条件不好,我和孩子爸爸都是从农村出来,很不容易上了...

    林玉珍阅读 1,603评论 0赞 1

  • 读 | 《挪威的森林》 渡边起初以为那只是个平庸无奇的水边栖生的黑色小虫而已,光芒微弱,颜色浅淡。而敢死队却一口咬...

    王小吹阅读 291评论 0赞 1

  • 1)Self-confidence is the belief that you can accomplish i...

  • 通过终端安装程序sudo apt-get install banner 时出错: E: Could not ge...