THTTPClient 访问仅 TLS 1.3 的站点会导致错误

发布于 2025-01-14 22:17:36 字数 921 浏览 1 评论 0原文

此代码:

uses
  System.Net.HttpClient;

procedure TForm2.Button1Click(Sender: TObject);
var
  LHTTP: THTTPClient;
  LResponse: IHTTPResponse;
begin
  LHTTP := THTTPClient.Create;
  try
    LHTTP.SecureProtocols := [THTTPSecureProtocol.TLS13];
    LResponse := LHTTP.Get('https://tls13.1d.pw'); // TLS 1.3 ONLY site
    if LResponse.StatusCode = 200 then
      ShowMessage('TLS 1.3 worked');
  finally
    LHTTP.Free;
  end;
end;

结果:

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class ENetHTTPClientException with message 'Error sending data: (12175) A security error occurred'.
---------------------------
Break   Continue   Help   Copy   
---------------------------

使用 Windows 10(相同的代码适用于 Windows 11)。我已进入 Windows 中的“Internet 选项”设置并启用了 TLS 1.3,但这并不能解决问题。

我还需要做什么吗?

This code:

uses
  System.Net.HttpClient;

procedure TForm2.Button1Click(Sender: TObject);
var
  LHTTP: THTTPClient;
  LResponse: IHTTPResponse;
begin
  LHTTP := THTTPClient.Create;
  try
    LHTTP.SecureProtocols := [THTTPSecureProtocol.TLS13];
    LResponse := LHTTP.Get('https://tls13.1d.pw'); // TLS 1.3 ONLY site
    if LResponse.StatusCode = 200 then
      ShowMessage('TLS 1.3 worked');
  finally
    LHTTP.Free;
  end;
end;

Results in:

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class ENetHTTPClientException with message 'Error sending data: (12175) A security error occurred'.
---------------------------
Break   Continue   Help   Copy   
---------------------------

Using Windows 10 (The same code works on Windows 11). I've gone into the Internet Options settings in Windows and enabled TLS 1.3, however that does not resolve the issue.

Anything else I need to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阿楠 2025-01-21 22:17:36

根据 WinHTTP 错误消息 文档:

ERROR_WINHTTP_SECURE_FAILURE

12175

在服务器发送的安全套接字层 (SSL) 证书中发现一个或多个错误。要确定遇到的错误类型,请检查 状态回调函数中的WINHTTP_CALLBACK_STATUS_SECURE_FAILURE通知。有关详细信息,请参阅WINHTTP_STATUS_CALLBACK< /代码>


不幸的是,THTTPClient 不为您提供使用此类回调的访问权限,但它确实使用内部回调来捕获其 SecureFailureReasons 属性。所以您可以检查以获取更多信息。

确定在 Windows 10 上启用了 TLS 1.3 吗?您使用的是 1903 版本或更高版本吗?早期版本不支持 TLS 1.3。

如何在 Windows 10 中启用 TLS 1.3

Per the WinHTTP Error Messages documentation:

ERROR_WINHTTP_SECURE_FAILURE

12175

One or more errors were found in the Secure Sockets Layer (SSL) certificate sent by the server. To determine what type of error was encountered, check for a WINHTTP_CALLBACK_STATUS_SECURE_FAILURE notification in a status callback function. For more information, see WINHTTP_STATUS_CALLBACK.

Unfortunately, THTTPClient does not provide access for you to use such a callback, but it does use an internal callback to capture the reason for ERROR_WINHTTP_SECURE_FAILURE in its SecureFailureReasons property. So you can check that for more info.

Are you sure you enabled TLS 1.3 on Windows 10? Are you using build 1903 or later? Earlier builds do not support TLS 1.3.

how to enable TLS 1.3 in windows 10

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文