🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #206

Re: Logging in with TIdHTTP

#206
From: Tom Byars
Date: Tue, 03 Jul 2007 10:55
95 lines
4209 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:4689349a@newsgroups.borland.com...
>
> "Tom Byars" <tam118118@hotmail.com> wrote in message
> news:46878587@newsgroups.borland.com...
>
>> On setting the HandleRedirection property to true I find that the
>> text returned is for the sites login / register web page. Opening an
>> IE window and manually logging in doesn't help. Is there a way of
>> logging in using TIdHTTP? If not, is there a way of finding where
>> the web site is looking for the cookies so I can put these in place
>> programatically.
>
> The website expects you to POST an input form containing your
> username/password.  You can do that very easily using a TStringList
> with the TIdHTTP::Post() method, ie:
>
>    TStringList *Fields = new TStringList;
>    try
>    {
>        Fields->Values["in_un"] = "username";
>        Fields->Values["in_pw"] = "password";
>
> IdHTTP1.Post("https://reg.racingpost.co.uk/cde/login_iframe.sd",
> Fields);
>    }
>    __finally
>    {
>        delete Fields;
>    }
>
> If successful, then your original Get() should work.  Something else
> to keep in mind - the above URL is a secure page, so make sure that
> you have an SSL-enabled IOHandler attached to the TIdHTTP beforehand.
>
>
> Gambit
>
>

Tom & Remy, thanks for the replies.

Remy, I'm using a TIdHTTP component called Betting with a 
TIdConnectionInterceptOpenSSL component called InterceptSSL. The .dfm file 
shows

object Betting: TIdHTTP
 Intercept = InterceptSSL
 InterceptEnabled = True
 HandleRedirects = True
 Request.Accept = 'text/html, */*'
 Request.ContentLength = 0
 Request.ContentRangeEnd = 0
 Request.ContentRangeStart = 0
 Request.ProxyPort = 0
 Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
end
object InterceptSSL: TIdConnectionInterceptOpenSSL
 SSLOptions.Method = sslvSSLv2
 SSLOptions.Mode = sslmUnassigned
 SSLOptions.VerifyMode = []
 SSLOptions.VerifyDepth = 0
end

I then tried the following code (much as you suggested)

AnsiString S;
TStringList *Login=new TStringList;
TStringStream *Response=new TStringStream(S);
Login->Values["in_un"]="username";
Login->Values["in_pw"]="password";
Betting->Post("https://reg.racingpost.co.uk/cde/login_iframe.sd",Login,Response);
S=Response->DataString;
delete Login;
delete Response;

After executing the above S contains the html for the login page again (so 
presumably it hasn't accepted the details) and the subsequent Get doesn't 
work (program seems to hang when executing the Get line).

Someone using a TCppWebBrowser component tells me that when you manually 
login on the home page the parameters for the BeforeNavigate2 procedure have 
the following values

PostData
in_un=username&in_pw=password&process=IN&PARGS=http%253A%252F%252Fwww.racingpost.co.uk%252Fnews%252Fhome.sd

Headers
Content-Type: application/x-www-form-urlencoded

TargetFrameName
hm_RP_Login

Can you give me any hints as to what goes where based on that as I'm totally 
lost. Apologies if that's all a bit long winded. 
Technical Details
Message-ID: <468a2b26$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <46878587@newsgroups.borland.com> <4689349a@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,e38d4989d40bbffa
X-Google-Attributes: gidfeeec,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Tom Byars" <tam118118@hotmail.com>
Newsgroups: borland.public.cppbuilder.internet.web
References: <46878587@newsgroups.borland.com> <4689349a@newsgroups.borland.com>
In-Reply-To: <4689349a@newsgroups.borland.com>
Subject: Re: Logging in with TIdHTTP
Date: Tue, 3 Jul 2007 11:55:49 +0100
Lines: 96
MIME-Version: 1.0
Content-Type: text/plain;
 format=flowed;
 charset="iso-8859-1";
 reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Windows Mail 6.0.6000.16480
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16480
NNTP-Posting-Host: 90.195.48.82
Message-ID: <468a2b26$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1183460134 90.195.48.82 (3 Jul 2007 03:55:34 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail