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

标签 delphi delphi-11-alexandria delphi-run-time-library

这段代码:

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,但这并不能解决问题。

我还需要做什么吗?

最佳答案

根据 WinHTTP Error Messages文档:

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.

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

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

how to enable TLS 1.3 in windows 10

关于delphi - THTTPClient 访问仅 TLS 1.3 的站点会导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71506537/

相关文章:

delphi - 在Delphi Alexandria RTL中,ScanChar()写得不好吗?

delphi - 如何阻止Delphi 11 "Close All"关闭IDE欢迎屏幕

azure - Delphi Web 应用程序为 Azure 提供可能性

delphi - win64\debug\dsnap.dcp 似乎已过时

delphi - 在光标处打开文件未在 IDE 中打开文件

delphi - 如何比较定义/实现顺序完全不同的两个大型 Delphi 单元?

delphi - 从 TObjectList 中提取一个对象

Delphi链接包时会发生什么?