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 idhttp使用代理ip

indy断点续传

Delphi 获取一个文件夹下的一级目录

Delphi 判断安卓app第一次启动

Delphixe4 版本中,已针对移动平台 引入了 arc 模型

Delphi 捕捉异常 try except语句 和 try finally语句用法以及区别

Delphi判断电脑连接到 internet 了吗?

Delphi xe6 android 查看电池信息

Delphi 得到字符串拼音首字母

Delphi webbrowser 加载html 将html代码转换成网页

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



打赏

取消

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

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

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

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

评论

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