Delphi 11 TIdHTTP.Get 结果无法加载 SSL 库

Delphi 11 TIdHTTP.Get results in Could not load SSL Library

在空白的 Delphi 11 项目中,我放下了一个按钮和一个 TIdHTTP 组件。

该按钮尝试获取 .txt 文件。

procedure TForm1.Button1Click(Sender: TObject);
var
  Stream: TMemoryStream;

begin
  Stream := TMemoryStream.Create;

    try

      IdHTTPGetProgramUpdateFile.Get('https://www.bookup.com/cowupdates/build129.txt', 
                                     Stream);

    except

      on E: Exception do
        begin
          MessageDlg(E.Message,
                     TMsgDlgType.mtInformation,
                     [TMsgDlgBtn.mbOK],
                     E.HelpContext);
        end;
    end;

  Stream.SaveToFile('downloaded.txt');

  Stream.Free;
end;

如果 Windows 项目使用 https 请求 URL,则错误为“无法加载 SSL 库”。

如果 Windows 或 Macintosh 上的项目使用 http 请求 URL,则错误为“301 永久移动”。 (文件在网站上。)

如果项目 运行 在 Macintosh 上使用 https,则 PAServer 报告项目“正在以不​​安全的方式加载 libcrypto”。

当运行ning for Windows时,项目在IdSSLOpenSSL.pas中抛出异常,源代码注释:

an exception here probably means that you are using the wrong version of the openssl libraries. refer to comments at the top of this file.

文件顶部的评论对我没有用。

我正在尝试从网站下载文本文件的内容,但我对 Internet 协议知之甚少。我错过了什么?

If the Windows project requests the URL with https then the error is "Could not load SSL Library."

您依赖 TIdHTTP 使用 Indy 的默认 TIdSSLIOHandlerSocketOpenSSL 组件,它依赖于 OpenSSL 1.0.2 库文件(即 libeay32.dllssleay32.dll 等) ,因此请确保将这些文件与您的应用程序一起部署,最好是在您应用程序的安装文件夹中。或者,如果需要,Indy 确实有一个 IdOpenSSLSetLibPath() 函数,您可以在应用程序启动时调用它来指定库所在的备用文件夹路径。

If the project on Windows or Macintosh requests the URL with http then the error is "301 Moved Permanently". (The file is on the web site.)

301 是重定向响应。服务器告诉您您请求的 URL 是旧的并且资源在不同的 URL 可用(在这种情况下,它可能会将您重定向到 HTTPS url),将在 TIdHTTP.Response.Location 属性 和 TIdHTTP.OnRedirect 活动中提供给您。

如果您将 TIdHTTP.HandleRedirects 设置为 true(默认为 false),则 TIdHTTP 将自动重新请求新的 URL你。否则,它会将 301 视为错误条件,您将不得不自己手动请求新的 URL。

If the project is run on a Macintosh with https then the PAServer reports the project "is loading libcrypto in an unsafe way."

默认情况下,在基于 'Nix 的系统上,Indy 尝试使用未版本化的符号链接加载 OpenSSL 库文件,如果失败,则它会回退到加载特定版本化的库文件。使用符号链接并不安全,因为它们可能映射到您不期望的库版本。例如,在现代系统上,OpenSSL 未版本化的符号链接可能映射到 OpenSSL 1.1.x 或更高版本的库文件,TIdSSLIOHandlerSocketOpenSSL 不支持(改为使用 this SSLIOHandler)。 Indy 具有 IdOpenSSLSetCanLoadSymLinks()IdOpenSSLSetLoadSymLinksFirst() 函数,您可以在应用程序启动时调用它们以防止 Indy 尝试加载符号链接。然后您可以使用您的应用程序部署特定版本的库文件,或将 Indy 指向它们所在的文件夹。

When running for Windows, the project throws an exception in IdSSLOpenSSL.pas with the source code comment:

an exception here probably means that you are using the wrong version of the openssl libraries. refer to comments at the top of this file.

文件顶部的评论对我没有用。

您可以在错误发生后使用 Indy 的 WhichFailedToLoad() 函数来查找 Indy 是否因为库文件失败或加载失败或缺少所需的函数导出而无法加载 OpenSSL。