一个关于TIDHTTP的多线程问题,各位高手帮忙看看!!谢谢(100分)

  • 主题发起人 主题发起人 PROSE
  • 开始时间 开始时间
P

PROSE

Unregistered / Unconfirmed
GUEST, unregistred user!
function TFormLogin.login():Boolean;
var
Responses : TStringStream ;
PostData: TStrings;
timekey,PHPSeesion,surl,tt :string;
Cookie,serverurl : string;
i : integer;
x :integer;
begin
LabMess.Caption :='准备登陆...';
timekey :=IntToStr(DateTimeToUnix(Now)-32400);
Responses := TStringStream.Create('');
PostData:=TStringlist.Create;
PostData.Add('timestamp='+timekey);
PostData.Add('v=2');
PostData.Add('login='+Utf8encode(FormLogin.EUsername.text));
PostData.Add('pass=' + Utf8encode(FormLogin.EPassword.text));
FormLogin.IdHTTP1.HandleRedirects := True;
serverurl := serverinifile.ReadString('SERVER_URL','Server'+IntToStr(FormLogin.ComboBox1.ItemIndex+1),'');
try try
FormLogin.IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded' ;

idHttp1.Post('http://'+serverurl+'/game/reg/login2.php', PostData, Responses);

x:= Pos('session=',Responses.DataString);
PHPSeesion := trim(Copy(Responses.DataString,x+8,12));
Except
on E: Exceptiondo
showmessage('Error encountered during POST: ' + E.Message);
end;
finally
FreeAndNIl(PostData);
ResPonses.Free;
end;

if Pos('<',PHPSeesion)>0 then
begin
//登陆失败
LabMess.Caption :='登陆失败,请重新登陆!';

end
else
begin
for i := 0 to FormLogin.idHttp1.Response.RawHeaders.Count -1do
if UpperCase(LeftStr(FormLogin.idHttp1.Response.RawHeaders, 10)) = 'SET-COOKIE' then
begin
Cookie := Trim(Copy(FormLogin.idHttp1.Response.RawHeaders, 12, MaxInt));
Cookie := Copy(Cookie, 1, Pos(';', Cookie) - 1);
FormLogin.idHttp1.Request.RawHeaders.Add('Cookie:'+ Cookie);
FormLogin.idHttp1.CookieManager.AddCookie(Cookie,serverurl);
end;
//登陆成功,处理User
LabMess.Caption :='初始化信息!';
User.StartTime := DateTimeToUnix(Now);
User.LastTime := StrToInt(serverinifile.ReadString('SER_INFO','lasttime','0'));
User.Universe := FormLogin.ComboBox1.ItemIndex+1;
User.System := serverurl;
User.LoginName := Utf8encode(FormLogin.EUsername.text);
User.LoginPassWord := Utf8encode(FormLogin.EPassword.text);
User.Login := True;
User.timeamp := StrToInt(serverinifile.ReadString('SER_INFO','timeamp','0'));
User.Session := PHPSeesion;
ImageBar.Width:= 15;
ImageRight.Left := ImageBar.left+ImageBar.Width;
end;
Result := User.Login;
end;

如何改写成多线程的方法
 
后退
顶部