delphi IDHTTP登录网站教程代码


下面代码是delphi2010的,主要区别也就在于stringstream的 初使化,
Response := TStringStream.Create(”, TEncoding.UTF8); 改成
Response := TStringStream.Create(‘ ‘);

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
StdCtrls;

type
TForm1 = class(TForm)
mmo1: TMemo;
btn1: TButton;
IdHTTP1: TIdHTTP;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
code: string;
done: Boolean;
postList: TStrings;
Response: TStringStream;
begin
mmo1.clear;

// 开始登录代码
Response := TStringStream.Create('', TEncoding.UTF8);
postList := TStringList.Create;
try
IdHTTP1.HandleRedirects := True;

postList.add('cktime=31536000');
postList.add('forward=');
postList.add('hideid=0');
postList.add('jumpurl=http://bbs.hualongxiang.com/index.php');
postList.add('lgt=0');
postList.add('pwpwd='+edit2.Text );
postList.add('pwuser='+edit1.Text );
postList.add('step=2');
postList.add('submit=¼');

IdHTTP1.Post('http://bbs.hualongxiang.com/login.php?', postList, Response);
done := True;
except
done := false;
end;

if (done) and (Pos('200 OK', IdHTTP1.ResponseText) <> 0) then
begin
code := IdHTTP1.Get('http://bbs.hualongxiang.com/index.php');
mmo1.lines.add(code);
end
else
begin
mmo1.lines.add('logon error,error code:' + IdHTTP1.Response.RawHeaders.Text);
end;
Response.Free;
postList.Free;

end;



end.

联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678