文章目录
  1. 1. 解决办法一:
  2. 2. 解决办法二
    1. 2.1. 更新补丁
    2. 2.2. 设置默认值
    3. 2.3. 验证系统
  3. 3. 解决办法三
  4. 4. 其他参考内容

描述:请求被中止: 未能创建 SSL/TLS 安全通道。Could not create SSL/TLS secure channel。

产生平台:Windows Server 2012,Windows 7 Service Pack 1(SP1)和Windows Server 2008 R2 SP1

解决办法一:

在HttpWebRequest前设置代码

ServicePointManager.Expect100Continue = true;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

解决办法二

  • 上面的方法没有效果,则为系统层面的问题了,对照你现在使用的系统更新系统补丁

更新以将TLS 1.1和TLS 1.2启用为Windows中WinHTTP中的默认安全协议,此更新提供对Windows Server 2012,Windows 7 Service Pack 1(SP1)和Windows Server 2008 R2 SP1中的传输层安全性(TLS)1.1和TLS 1.2的支持,参考官方文档https://support.microsoft.com/en-us/help/3140245/update-to-enable-tls-1-1-and-tls-1-2-as-default-secure-protocols-in-wi

更新补丁

设置默认值

  • 在SChannel组件级别的Windows 7上启用TLS 1.1和1.2 (采用以下2.1或2.2一种更新)

2.1、微软安装更新注册表:http://download.microsoft.com/download/0/6/5/0658B1A7-6D2E-474F-BC2C-D69E5B9E9A68/MicrosoftEasyFix51044.msi

2.2、手动更新注册表,复制下面注册表代码导入到注册表。新建txt,将后缀txt改为reg(注册表项),导入(导入之前做备份)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[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

验证系统

  • 验证系统是否支持TLS1.2、TLS1.3

PowerShell打开:

Net.ServicePointManager::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3 -bor [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

解决办法三

  • 前面两种办法都不行,只能使用终极办法,升级系统到windows 10。

其他参考内容

https://blogs.perficient.com/2016/04/28/tsl-1-2-and-net-support/

存在解决方案,但是它们取决于框架版本:

.NET 4.6及更高版本。您无需执行任何其他工作即可支持TLS 1.2,默认情况下支持该功能。

.NET 4.5。支持TLS 1.2,但它不是默认协议。您需要选择使用它。以下代码将TLS 1.2设置为默认值,请确保在连接到安全资源之前执行它:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

.NET 4.0。不支持TLS 1.2,但是如果系统上安装了.NET 4.5(或更高版本),那么即使您的应用程序框架不支持TLS 1.2,您仍然可以选择使用TLS 1.2。唯一的问题是.NET 4.0中的SecurityProtocolType没有TLS1.2的条目,因此我们必须使用此枚举值的数字表示形式:
ServicePointManager.SecurityProtocol =(SecurityProtocolType)3072;

.NET 3.5或更低版本。不支持TLS 1.2(*),并且没有解决方法。将您的应用程序升级到该框架的最新版本。

PS对于场景3,还有一个注册表黑客,默认情况下会强制4.5使用TLS 1.2,而无需以编程方式强制执行。
PPS正如Microsoft的Christian Pop在下面提到的那样,.NET 3.5有一个可用的最新补丁程序,它启用了TLS1.2支持。
请参阅:
KB3154518 – Reliability Rollup HR-1605 – NDP 2.0 SP2 – Win7 SP1/Win 2008 R2 SP1
KB3154519 – Reliability Rollup HR-1605 – NDP 2.0 SP2 – Win8 RTM/Win 2012 RTM
KB3154520 – Reliability Rollup HR-1605 – NDP 2.0 SP2 – Win8.1RTM/Win 2012 R2 RTM
KB3156421 -1605 HotFix Rollup through Windows Update for Windows 10.

文章目录
  1. 1. 解决办法一:
  2. 2. 解决办法二
    1. 2.1. 更新补丁
    2. 2.2. 设置默认值
    3. 2.3. 验证系统
  3. 3. 解决办法三
  4. 4. 其他参考内容