NOP
NOP

Reputation: 95

How can my program log in to a Web site programmatically with Indy?

I am trying to log in to fileserve.com from my Delphi application.

I used the LiveHTTPHeader Firefox addon to see HTTP post data. I found

&autoLogin=on&recaptcha_response_field=&recaptcha_challenge_field=&recaptcha_shortencode_field=&loginFormSubmit=Login

I tried in my application like this:

Str := TStringList.Create;
Str.Add('loginUserName='+edit1.Text);
Str.Add('loginUserPassword='+edit2.Text);
Str.Add('autoLogin=on');
Str.Add('recaptcha_response_field=');
Str.Add('recaptcha_challenge_field=');
Str.Add('recaptcha_shortencode_field=');
Str.Add('loginFormSubmit=Login');  
s:= IdHTTP1.Post('http://www.fileserve.com/login.php', Str);
FreeAndNil(str);
s1 := IdHTTP1.Get('http://www.fileserve.com/dashboard.php');
memo1.lines.add(s1);

In my my memo, it's not giving the data after I logged in. It just displays the source of the main site. Why doesn't it recognize that I logged in? (I used a working ID and password while testing.)

I am using Delphi 7 and Indy 9; The IdHTTP.HandleRedirect property is set to true.

Upvotes: 2

Views: 2224

Answers (1)

Rob Kennedy
Rob Kennedy

Reputation: 163257

The site you're logging in to probably sends a cookie in its response to the login request. You need to remember that cookie and send it back during all subsequent requests. Indy should have some sort of TIdCookieManager object that you can hook up to your TIdHTTP object to make it remember cookies automatically.

Upvotes: 4

Related Questions