下面是我写的论坛自动登陆代码,但总是登陆不成功,不知道问题出在哪里?
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP;type
  TForm1 = class(TForm)
    Button1: TButton;
    IdHTTP: TIdHTTP;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
const
  BaseURL  = 'http://bbs.hangzhou.com.cn/';     //论坛所在地址
  UserName = '';    //登录用户名
  Password = '';    //登录密码
var
  Params: TStrings;
  HTML: String;
  MD5Pass: String;
  p1,p2: Integer;
begin
  Params:=TStringList.Create;
    Params.Add('username='+UserName);
    Params.Add('password='+Password);
    Params.Add('cookietime='+InttoStr(CookieNone));    Params.Add('comeurl='+BASEURL+'logging.php?action=login');
    HTML:=IdHttp.Post(BaseURL+'logging.php?action=login',Params);
    if Pos(BASEURL+'index.php',HTML)=0 then
    begin
      ShowMessage('登录失败');
      Exit;
    end
    else
      ShowMessage('登陆成功');
    end;
end.

解决方案 »

  1.   

    //我对Delphi的网络编程不懂, 帮你修改了一下, 你试试看行不行
    const
      BaseURL  = 'http://bbs.hangzhou.com.cn/';     //论坛所在地址
      UserName = '';    //登录用户名
      Password = '';    //登录密码
    var
      Params:string;
      HTML: String;
      MD5Pass: String;
      p1,p2: Integer;
    begin
      Params:=Format('UserName=%s&Password=%s&CookieTime=%s', [UserName, Password, InttoStr(CookieNone)]); 
      HTML:=IdHttp.Post(BaseURL+'logging.php?action=login',Params);
      if Pos(BASEURL+'index.php',HTML)=0 then begin
        ShowMessage('登录失败');
        Exit;
      end else
          ShowMessage('登陆成功');
      end;
    end.
      

  2.   

    Params:=Format('UserName=%s&Password=%s&CookieTime=%s', [UserName, Password, InttoStr(CookieNone)]); 
    这里的InttoStr(CookieNone)好像不对么
      

  3.   

    改成
    Params:=Format('UserName=%s&Password=%s&CookieTime=%s', [UserName, Password, DateToStr(Now())]);
      

  4.   

    你得处理好cookie建议用抓包软件分析
      

  5.   

    这种方法麻烦。因为idhttp提交的是数据本身,而通过浏览器提交的是表单,表单里不仅仅是你的username和password,还有很多内容。你可以通过编写isapi扩展截获浏览器提交的内容然后分析浏览器提交的格式
      

  6.   

    先使用Visual Sniffer抓包,看看用IE登陆的时候发送了哪些数据。
      

  7.   

    uses MSHTML
    procedure TForm1.btn2Click(Sender: TObject);
    begin
        wb1.Navigate('http://bbs.hangzhou.com.cn/logging.php?action=login');
    end;procedure TForm1.btn1Click(Sender: TObject);
    var
      o : Olevariant;
    begin
      try
        o := Wb1.OleObject.document.all.item('username',0);
        o.value := '111321';
        o := Wb1.oleobject.document.all.item('password',0);
        o.value := '111111';
        o :=Wb1.oleobject.document.all.item('loginsubmit',0);
        o.Click;
      except
      end;
    end;