Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Oct : IdHTTP Component - Error when Calling Get Method for Https URL
| Subject: | IdHTTP Component - Error when Calling Get Method for Https URL |
| Posted by: | "David Compton" (david.w.compt..@gmail.com) |
| Date: | Wed, 11 Oct 2006 06:51:58 +0000 (UTC) |
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.compton@gmail.com