简体   繁体   中英

Using Indy OpenSSL on Linux / Lazarus

I would like to retrieve results of Google search by Lazarus component TIdHTTP , part of Indy.

I have seen this already. I can use CUrl to retrieve some results.

To do the same with TIdHTTP , I have this :

queries:= TStringList.Create;
engine := 'http://www.google.com/search';
queries[0] := '?q=inurl:"foo"';
for i := 0 to queries.Count-1 do
begin
  Memo1.Lines.Add('Asking for : ' + engine + queries[i]);
  try
     IdHTTP1.Get(engine+queries[i], response);
     response.Position := 0;
     Memo2.Lines.LoadFromStream(response);
  finally
    response.Free;
  end;
end;              

The IdHTTP component's UserAgent property is set to Firefox/12.0 (property browser > request > UserAgent > Firefox/12.0 with upper case F). However, that is giving me this error :

"Project project1 raised exception class EIdIOHandlerPropInvalid with the message 'IOHandler value is not valid'"

In file 'xyz ... IdHTTP.pas at line 939
raise EIdIOHandlerPropInvalid.Create(RSIOHandlerPropInvalid)

That was translated from German to English.

Googling the error leads to this question on SO . I realize that it has something to do with an http request being redirected to an http s server. However, the answer to the other SO question is targeted on windows platform.

Question :

Could anyone please help me to tell me how to implement the same on Linux platform where the mentioned DLLs (libeay32.dll, ssleay32.dll) do not exist?

I have tried out the solution without caring for the DLLs - it results in a new error :

"Project project1 has raised exception class EIdOSSLCouldNotLoadSSLLibrary with the message 'Couldn't load SSL library'"

Note :

core/openssl 1.0.2.k-1 is installed. Linux is Manjaro (64-bit).

EIdIOHandlerPropInvalid means TIdHTTP was instructed to send an HTTPS request but the TIdHTTP.IOHandler property had not been assigned an SSLIOHandler component (such as TIdSSLIOHandlerSocketOpenSSL ) to handle the encryption.

Since you are sending a request to an HTTP URL, that means the server must be sending back an HTTP redirect to an HTTPS URL, and you have the TIdHTTP.HandleRedirects property set to true.

You must assign an SSLIOHandler component in order for TIdHTTP to send HTTPS requests. Had you sent a request directly to an HTTPS URL, TIdHTTP could handle that assignment for you (see this blog article for details), but since you are sending to an HTTP URL first, you will have to assign the IOHandler manually beforehand.

The solution you read about for Windows will also work for other platforms, including Linux. You just have to distribute the appropriate OpenSSL binaries if they don't already exist (Linux uses .so files, not .dll files), and optionally call Indy's IdOpenSSLSetLibPath() function at runtime to let Indy know where the binaries are located.

You are not limited to OpenSSL specifically. That just happens to be Indy's default SSL/TLS library of choice. But you can use any SSL/TLS library you want, as long as you can find (or write) a custom TIdSSLIOHandlerSocketBase -derived class to wrap it. Some 3rd party SSL/TLS libraries do provide an Indy IOHandler class (for instance, Eldos SecureBlackBox).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM