没办法,如果用COOKIES,最好用twebbrowser,, 如果非用tidhttp,则要用
idHttp和idCookieManager配合一起使用
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdCookieManager, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
type
TForm1 = class(TForm)
http: TIdHTTP;
CookieMngr: TIdCookieManager;
edtUserName: TLabeledEdit;
edtPassword: TLabeledEdit;
btnLogin: TButton;
Cookies: TMemo;
Memo1: TMemo;
btnInfor: TButton;
Button1: TButton;
edtSN: TLabeledEdit;
procedure btnLoginClick(Sender: TObject);
procedure btnInforClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//这个函数是登陆页面,
procedure TForm1.btnLoginClick(Sender: TObject);
var
s, s1: TStringStream;
i: Integer;
begin
s := TStringStream.Create('');
s1 := TStringStream.Create('');
try
//{
s.WriteString('action=LOGIN&gameSelect=gkk&');
s.WriteString('acct=' + edtUserName.Text + '&');
s.WriteString('pwd=' + edtPassword.Text);
http.Request.ContentType := 'application/x-www-form-urlencoded';
try
http.Post('http://register.kok.com.cn/billing/servlet/walletServlet', s, s1)
except
http.Get(http.Response.Location, s1);
end;
//}
Memo1.Lines.Text := s1.DataString;
//下面的是显示cookies信息的代码
Cookies.Clear;
for i := 0 to CookieMngr.CookieCollection.Count - 1 do
Cookies.Lines.Add(CookieMngr.CookieCollection.Items.CookieText);
finally
s.Free;
s1.Free;
end;
end;
//这是KOK注册页面中,显示帐户信息的函数
procedure TForm1.btnInforClick(Sender: TObject);
var
s, s1: TStringStream;
i: Integer;
begin
{
<form action=../servlet/walletServlet method=post>
<input type=submit value="修改个人资料">
<input type=hidden name=action value=INFO>
</form>
}
s := TStringStream.Create('');
s1 := TStringStream.Create('');
try
s.WriteString('action=INFO');
http.Request.ContentType := 'application/x-www-form-urlencoded';
try
http.Post('http://register.kok.com.cn/billing/servlet/walletServlet', s, s1)
except
http.Get(http.Response.Location, s1);
end;
Memo1.Lines.Text := s1.DataString;
Cookies.Clear;
for i := 0 to CookieMngr.CookieCollection.Count - 1 do
Cookies.Lines.Add(CookieMngr.CookieCollection.Items.CookieText);
finally
s.Free;
s1.Free;
end;
end;
end.