我的程序如何使用Indy以编程方式登录到Web站点?

时间:2011-02-20 22:11:10

标签: delphi http indy

我正在尝试从我的Delphi应用程序登录到fileserve.com。

我使用LiveHTTPHeader Firefox插件查看HTTP帖子数据。我找到了

  

&安培;自动登录= ON&安培; recaptcha_response_field =安培; recaptcha_challenge_field =安培; recaptcha_shortencode_field =安培; loginFormSubmit =登录

我试着在我的应用程序中这样做:

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);

在我的备忘录中,我登录后没有提供数据。它只显示主站点的来源。为什么不识别我登录? (我在测试时使用了工作ID和密码。)

我正在使用Delphi 7和Indy 9; IdHTTP.HandleRedirect属性设置为true。

1 个答案:

答案 0 :(得分:4)

您登录的网站可能会在其对登录请求的响应中发送cookie。您需要记住该cookie并在所有后续请求中将其发回。 Indy应该有某种TIdCookieManager对象,你可以连接到你的TIdHTTP对象,让它自动记住cookie。