从德尔福登录网站 [英] Log in to website from Delphi

查看:123
本文介绍了从德尔福登录网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会问,如果有人很善于向我解释如何从Delphi应用程序登录网页。我在这里发现的所有例子都证明对我没用,或者我做错了事情。我厌倦了搜索和代码不起作用。

I would ask if someone was kind enough to explain to me how to login at webpage from Delphi app. All the examples I've found here have proved useless to me or I'm doing something wrong. I'm tired of the search and the code that does not work.

没有错误消息,我甚至将页面代码写入备忘录,但似乎是从登录页面(不是帐户[仪表板]页面)的代码) - 似乎这段代码不能通过验证,我不知道为什么。

There is no error message, I even get page code into Memo but seems it's code from login page (not account [dashboard] page) - seems this code can't pass auth at all and I don't know why.

此代码有什么问题:

procedure Login;
var
 HTTP: TIdHTTP;
 Param: TStringList;
 S: String;
begin
 HTTP := TIdHTTP.Create(nil);
 HTTP.CookieManager := Main_Form.CookieManager;
 Param := TStringList.Create;
 Param.Clear;
 Param.Add('login=example');
 Param.Add('password=example');

try
 HTTP.Get ('http://www.filestrum.com/login.html');
 HTTP.Post('http://www.filestrum.com/login.html', Param);
 S := HTTP.Get ('http://www.filestrum.com/?op=my_account');
 Main_Form.Memo2.Lines.Add(S);
finally
  HTTP.Free;
  Param.Free;
end;
end;

或此版本:

procedure Login;
var
 HTTP: TIdHTTP;
 S: String;
begin  
 HTTP                             := TIdHTTP.Create(nil);
 HTTP.CookieManager               := Main_Form.CookieManager;
 HTTP.Request.BasicAuthentication := True;
 HTTP.Request.Username            := 'example';
 HTTP.Request.Password            := 'example';
 HTTP.AllowCookies                := True;
 HTTP.HandleRedirects             := True;

 S := HTTP.Get ('http://www.filestrum.com/?op=my_account');
 Main_Form.Memo2.Lines.Add(S);
end;

使用Delphi XE2,没有办法使此代码运行并登录。与XE3演示相同。正如我所说,我真的很疲倦的搜索一些解决方案,浪费日子,没有任何东西。

Used Delphi XE2 and there is no way to make this code running and login. It's same with XE3 demo. As I said, I'm really tired searching some solution, waste days into it and nothing.

请大家帮忙一些。真的需要它。

Please guys, some help here. Really need it.

推荐答案

尝试这样的东西:

function Login: string;
var
  IdHTTP: TIdHTTP;
  Request: TStringList;
  Response: TMemoryStream;
begin
  Result := '';
  try
    Response := TMemoryStream.Create;
    try
      Request := TStringList.Create;
      try
        Request.Add('op=login');
        Request.Add('redirect=http://www.filestrum.com');
        Request.Add('login=example');
        Request.Add('password=example');
        IdHTTP := TIdHTTP.Create;
        try
          IdHTTP.AllowCookies := True;
          IdHTTP.HandleRedirects := True;
          IdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
          IdHTTP.Post('http://www.filestrum.com/', Request, Response);
          Result := IdHTTP.Get('http://www.filestrum.com/?op=my_account');    
        finally
          IdHTTP.Free;
        end;
      finally
        Request.Free;
      end;
    finally
      Response.Free;
    end;
  except
    on E: Exception do
      ShowMessage(E.Message);
  end;
end;

这篇关于从德尔福登录网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆