如何使用 Tls 1.3 处理 HttpWebRequest C#

use*_*129 14 ssl httpwebrequest tls1.3

由于以下错误消息,我无法使用 WebRequest 连接到 HTTPS 服务器 (TLS 1.3):

请求被中止:无法创建 SSL/TLS 安全通道。

以前的 TLS 版本是 1.2,使用下面的代码我可以正确获取页面,但随着页面 ssl 升级到 TLS 1.3,我收到错误,而且我找不到任何解决方案:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Run Code Online (Sandbox Code Playgroud)

其实我觉得应该是这样的:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
Run Code Online (Sandbox Code Playgroud)

但没有。

Ric*_*ane 12

看起来 TLS13 现在作为 4.8 .Net Framework 的一部分受到支持

https://learn.microsoft.com/en-us/dotnet/api/system.net.securityprotocoltype?view=netframework-4.8

但是,它仅在较新的 Window 操作系统版本(Windows 11 和 Server 2022+)上受支持,请参阅此处了解完整的支持详细信息。

  • 4.8 声明 `SecurityProtocolType.Tls13` 常量。不幸的是,由于 .NET 使用 Schannel,因此尚不支持 TLS 1.3。根据https://learn.microsoft.com/en-us/windows/win32/secauthn/protocols-in-tls-ssl--schannel-ssp-#tls-protocol-version-support,它应该支持 TLS 1.3 Windows Server 2022。 (5认同)