如何在 Delphi 中下载一个非常简单的 HTTPS 页面? [英] How to download a very simple HTTPS page in Delphi?

查看:59
本文介绍了如何在 Delphi 中下载一个非常简单的 HTTPS 页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了在此处看到的代码,但它不适用于 HTTPS.我需要将此页面下载为字符串,并在其上添加一些 Break 行以将信息按顺序排列在 TMemo 中.

I tried a code I saw here but it didn't work for HTTPS. I need to download this page as a String, and add some Break lines on it to put the informations in order in a TMemo.

怎么做?我尝试使用 Indy 但由于 SSL 失败.

How to do it? I tried to use Indy but I failed because of the SSL.

我尝试了这个页面的解决方案:如何下载一个网页变成一个变量?

I tried the solutions of this page: How to download a web page into a variable?

如何下​​载此页面 https://api.rastrearpedidos.com.br/api/rastreio/v1?codigo=OP133496280BR 那只是纯文本并放入字符串中?并像这样格式化,在 TMemo 的行中:

How to download this page https://api.rastrearpedidos.com.br/api/rastreio/v1?codigo=OP133496280BR thats just pure text and put in in a String? and also format it like that, in the lines of a TMemo:

"Objeto em trânsito - por favor aguarde"
"cidade":"SAO JOSE DOS CAMPOS"
"uf":"SP"
"dataHora":"18/06/2021 16:53"
"descricao":"Objeto postado","cidade":"SAO JOSE DOS CAMPOS","uf":"SP"

这是葡萄牙语,英语不是我的第一语言.谢谢你们,如果你们能帮助我.我使用 Embarcadero Delphi 10.2 Tokyo.

It's portuguese, English isn't my first language. Thanks if you guys could help me. I Use the Embarcadero Delphi 10.2 Tokyo.

推荐答案

当使用 Indy 时,假设您使用 Indy 的默认 TIdSSLIOHandlerSocketOpenSSL 组件来支持 SSL/TLS,那么请确保您将 2 OpenSSLDLL,ssleay32.dlllibeay32.dll,与您的 EXE 位于同一文件夹中.您可以从这里获取它们:

When using Indy, assuming you are using Indy's default TIdSSLIOHandlerSocketOpenSSL component for SSL/TLS support, then make sure you put the 2 OpenSSL DLLs, ssleay32.dll and libeay32.dll, in the same folder as your EXE. You can get them from here:

https://github.com/IndySockets/OpenSSL-Binaries

请注意,TIdSSLIOHandlerSocketOpenSSL 最多仅支持 OpenSSL 1.0.2.如果您需要使用 OpenSSL 1.1.x(对于 TLS 1.3+ 等),则 使用此SSLIOHandler 代替.您必须从其他地方获取相关的 OpenSSL DLL,或者自己编译它们.

Note that TIdSSLIOHandlerSocketOpenSSL only supports up to OpenSSL 1.0.2. If you need to use OpenSSL 1.1.x instead (for TLS 1.3+, etc), then use this SSLIOHandler instead. You will have to obtain the relevant OpenSSL DLLs from elsewhere, or compile them yourself.

无论哪种方式,一旦您决定要使用哪个 SSLIOHandler,代码就相当简单:

Either way, once you decide which SSLIOHandler you want to use, the code is fairly simple:

var
  HTTP: TIdHTTP;
  SSL: TIdSSLIOHandlerSocketOpenSSL;
  Response: string;
begin
  HTTP := TIdHTTP.Create(nil);
  try
    // configure HTTP as needed (version, headers, etc)...

    SSL := TIdSSLIOHandlerSocketOpenSSL.Create(HTTP);
    // configure SSL as needed (TLS versions, certificates, etc)...
    HTTP.IOHandler := SSL;

    Response := HTTP.Get('https://api.rastrearpedidos.com.br/api/rastreio/v1?codigo=OP133496280BR');
  finally
    HTTP.Free;
  end;
  
  // use Response as needed...
end;

这篇关于如何在 Delphi 中下载一个非常简单的 HTTPS 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆