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.

相关阅读 >>

Delphi 递归搜索文件夹子目录

Delphi isipadress 非正则表达式验证ip的方法

Delphi 在vcl中显示一个非激活状态的窗口

Delphi adotable1 链接mdb数据库

Delphi 2009 泛型容器单元(generics.collections)[3]: tstack<t>

Delphi 掌控pagecontrol中的右上方的左右箭头事件

Delphi 时间增加一小时的技巧

Delphi图像细化处理

Delphi多媒体函数

Delphi gb2312 编码转义url字符串

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...