Ingo
Ingo

Reputation: 5381

Can't open Https TSL page with Delphi - Indy Error : SSL23_GET_SERVER_HELLO

I want to read an HTML page via HTTPS using Indy's TIdHTTP in Delphi XE5.

ssleay32.dll and libeay32.dll are in the main program folder.

I am getting an error: SSL23_GET_SERVER_HELLO. What can I do to fix this?

function get_page_text:string;
var
  Response: String;
  HTTPClient: TidHTTP;
const
  url = 'https://www.lustundreiz.com/login';
begin
  HTTPClient := TidHTTP.Create;
  HTTPClient.AllowCookies := True;
  HTTPClient.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  Response := HTTPClient.get(url);
  HTTPClient.Free;
  result := response;
end;

Upvotes: 1

Views: 2971

Answers (2)

Ingo
Ingo

Reputation: 5381

Ok, after I updated from Delphi XE5 to Delphi XE10 the Code works well without any Errors. Thanks to Remy for the Support.

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 598448

The default SSL/TLS version used by TIdSSLIOHandlerSocketOpenSSL when you don't specify a version is TLSv1, not SSLv23. So it is very unusual for you to be getting an SSL23 error.

Many modern web servers now require TLS 1.1 or higher, TLS extensions like SNI, etc. So consider enabling sslvTLSv1_1 and sslvTLSv1_2 in the TIdSSLIOHandlerSocketOpenSSL.SSLOptions.SSLVersions property, in addition to the default sslvTLSv1. And make sure you are using an up-to-date version of Indy and the OpenSSL DLLs to support those versions.

You should also wrap your code in a try..finally so you can Free the TIdHTTP object even if Get() raises an exception.

Try this:

function get_page_text:string;
var
  HTTPClient: TIdHTTP;
  SSL: TIdSSLIOHandlerSocketOpenSSL;
const
  url = 'https://www.lustundreiz.com/login';
begin
  HTTPClient := TIdHTTP.Create;
  try
    HTTPClient.AllowCookies := True;
    // set other HTTP properties as needed...

    SSL := TIdSSLIOHandlerSocketOpenSSL.Create(HTTPClient);
    SSL.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2];
    // set other SSL properties as needed...
    HTTPClient.IOHandler := SSL;

    Result := HTTPClient.Get(url);
  finally
    HTTPClient.Free;
  end;
end;

Upvotes: 2

Related Questions