Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IdHTTP Component - Error when Calling Get Method for Https URL

3,056 views
Skip to first unread message

David Compton

unread,
Oct 11, 2006, 2:51:58 AM10/11/06
to
I'm trying to automate the task of downloading a file from a https web site.
I'm just starting out and using the Indy IdHTTP component to try to send
a Get request to the URL. My problem is that I get the following error:

"An existing connection was forcibly closed by the remote host" when the
Get method is called. I've done a considerable amount of research on the
web in the process of getting to this point and have taken into account the
following factors:

Setting the Linger Socket Option
Assigning a IdSSLIOHandlerSocketBase to the IdHTTP.IOHandler
Downloading the required SSL dll's and saving them into my application root
directory

The relevant parts of my code are below:

It is the ReturnedPage:= https.Get(URL); line that generates the error.
................................


TMyIdSSLIOHandlerSocketBase = class(TIdSSLIOHandlerSocketBase)
protected
FLinger: Boolean;
procedure DoAfterBind; override;
procedure SetLinger(Value: Boolean);
procedure SetLingerOpt;
public
property Linger: Boolean read FLinger write SetLinger;
function Clone : TIdSSLIOHandlerSocketBase; override;
procedure StartSSL; override;
end;

........................


procedure TMainForm.Button1Click(Sender: TObject);
var
https: TIdHTTP;
URL: string;
ReturnedPage: string;
SSLIOHandler: TMyIdSSLIOHandlerSocketBase;
begin
SSLIOHandler:= TMyIdSSLIOHandlerSocketBase.Create;
SSLIOHandler.Linger := true;
URL := 'https://advisers.macquarie.com.au/security/login.html';
https := TIdHTTP.Create(nil);
try
https.IOHandler := SSLIOHandler;
TMyIdSSLIOHandlerSocketBase(https.IOHandler).URIToCheck := URL;
ReturnedPage:= https.Get(URL);
MessagesMemo.Text := ReturnedPage;
finally
https.Free;
SSLIOHandler.Free;
end;
end;

{ TMyIdSSLIOHandlerSocketBase }

function TMyIdSSLIOHandlerSocketBase.Clone: TIdSSLIOHandlerSocketBase;
begin
inherited
end;

procedure TMyIdSSLIOHandlerSocketBase.StartSSL;
begin
inherited
end;

procedure TMyIdSSLIOHandlerSocketBase.DoAfterBind;
begin
SetLingerOpt;
inherited;
end;

procedure TMyIdSSLIOHandlerSocketBase.SetLinger(Value: Boolean);
begin
if FLinger <> Value then
begin
FLinger := Value;
SetLingerOpt;
end;
end;

procedure TMyIdSSLIOHandlerSocketBase.SetLingerOpt;
begin
if BindingAllocated then
begin
if FLinger then
FBinding.SetSockOpt(SocketOptionLevel.Socket, SocketOptionName.Linger,
1)
else
FBinding.SetSockOpt(SocketOptionLevel.Socket, SocketOptionName.DontLinger,
1);
end;
end;

Regards,
David Compton
mailto:david.w...@gmail.com

Remy Lebeau (TeamB)

unread,
Oct 11, 2006, 3:32:28 AM10/11/06
to

"David Compton" <david.w...@gmail.com> wrote in message
news:94596682342c8...@newsgroups.borland.com...

> My problem is that I get the following error:
>
> "An existing connection was forcibly closed by the remote host" when the
> Get method is called.

WSAECONNRESET (10054)

Connection reset by peer.

A existing connection was forcibly closed by the remote host. This
normally results if the peer application on the remote host is suddenly
stopped, the host is rebooted, or the remote host used a "hard close" (see
setsockopt for more information on the SO_LINGER option on the remote
socket.)

> Downloading the required SSL dll's and saving them into my application
root
> directory

Which version of Indy are you using? Which DLLs did you download?

> TMyIdSSLIOHandlerSocketBase = class(TIdSSLIOHandlerSocketBase)

You need to use TIdSSLIOHandlerSocketOpenSSL, not TIdSSLIOHandlerSocketBase
directly. Your code is not actually implementing SSL at all. You are
bypassing Indy's use of the OpenSSL DLLs altogether.


Gambit


David Compton

unread,
Oct 11, 2006, 4:02:00 AM10/11/06
to
Hello Remy,

Thanks for your reply.

I'm using Indy version 10.1.5 in Delphi 2006.

I downloaded the dll's from http://www.intelicom.si/ (indy_openssl096g),
they are dated 13/08/2002. Although I also have a later version of these
dll's downloaded from elsewhere (indy-openssl-library-0.9.7j) dated 25/06/2006.
Which version should I be using - or are neither of these correct?

Also which unit do I find TIdSSLIOHandlerSocketOpenSSL in? I can't find
any reference to it in the online help.

Regards,
David Compton
mailto:david.w...@gmail.com

> "David Compton" <david.w...@gmail.com> wrote in message

Remy Lebeau (TeamB)

unread,
Oct 12, 2006, 1:26:18 AM10/12/06
to

"David Compton" <david.w...@gmail.com> wrote in message
news:94596682348e8...@newsgroups.borland.com...

> I'm using Indy version 10.1.5 in Delphi 2006.
>
> I downloaded the dll's from http://www.intelicom.si/ (indy_openssl096g),
> they are dated 13/08/2002.

Then you are using the wrong DLLs (and very outdated ones at that). Indy
10.1.5 uses the official DLLs from http://www.openssl.org now.

> Although I also have a later version of these dll's downloaded from
elsewhere
> (indy-openssl-library-0.9.7j) dated 25/06/2006.

Those are still the wrong DLLs. Indy 10 no longer uses custom-built DLLs
anymore.

> Also which unit do I find TIdSSLIOHandlerSocketOpenSSL in?

IdSSLOpenSSL


Gambit


David Compton

unread,
Oct 12, 2006, 5:26:17 AM10/12/06
to
Hello Remy,

I'm making progress -thanks for your continued help.

I have now downloaded the latest dll's and am using TIdSSLIOHandlerSocketOpenSSL.
My code is a lot simpler now.

However I'm getting an erro when I try to run the application:

"Could not load SSL library"

Is it enough to put the following 3 dll's in my application folder:

libssl32.dll
ssleay32.dll
libeay32.dll

Regards,
David Compton
mailto:david.w...@gmail.com

> "David Compton" <david.w...@gmail.com> wrote in message

David Compton

unread,
Oct 12, 2006, 6:02:04 AM10/12/06
to
Here is my new "simplified" code - just in case that helps in answering my
latest query.

unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdHTTP, IdSSLOpenSSL;

type
TMainForm = class(TForm)
Button1: TButton;
MessagesMemo: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.Button1Click(Sender: TObject);
var
https: TIdHTTP;
URL: string;
ReturnedPage: string;

SSLIOHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
SSLIOHandler:= TIdSSLIOHandlerSocketOpenSSL.Create;
URL := 'http://www.google.com.au';
//URL := 'https://advisers.macquarie.com.au/security/login.html';


https := TIdHTTP.Create(nil);
try
https.IOHandler := SSLIOHandler;

ReturnedPage:= https.Get(URL);
MessagesMemo.Text := ReturnedPage;
finally
https.Free;
SSLIOHandler.Free;
end;
end;

end.

David Compton

unread,
Oct 12, 2006, 9:37:44 PM10/12/06
to
I've got this problem sorted out now. It seems that I needed to call IdSSLOpenSSLHeaders.Load
in my code to get the
SSL library loaded.

Remy Lebeau (TeamB)

unread,
Oct 12, 2006, 10:47:46 PM10/12/06
to

"David Compton" <david.w...@gmail.com> wrote in message
news:945966823aff8...@newsgroups.borland.com...

> It seems that I needed to call IdSSLOpenSSLHeaders.Load in
> my code to get the SSL library loaded.

Load() is called automatically by TIdSSLIOHandlerSocketOpenSSL when it goes
to establish its first connection. You do not need to call Load() in your
own code at all.


Gambit


David Compton

unread,
Oct 13, 2006, 3:30:55 AM10/13/06
to
Hello Remy,

Calling Load manually was the only way that I could get around the "Could
not load SSL library" error.

If I should not be calling Load manually then do you have any other suggestions
as to how to resolve that error?


Regards,
David Compton
mailto:david.w...@gmail.com

> "David Compton" <david.w...@gmail.com> wrote in message

0 new messages