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 tfdconnection只能取得50处理

Delphi整理二(object pascal语言)

Delphi中的sender:tobject对象解析

Delphi [android]获取屏幕的物理分辨率

Delphi定位注册表指定键位

Delphi 字符串替换

Delphi edit控制字居中,居左,居右

Delphi 屏幕dpi计算

Delphi获取操作系统安装磁盘盘符

Delphi 10.3 开发app 在android手机上获取imei

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



打赏

取消

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

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

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

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

评论

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