现在情况主程序多次调用TouchURl时候出错,为什么?library TouchClient;
uses
SysUtils,
Classes,
wTouch in 'wTouch.pas';{$R *.res}function TouchUrl(Url:string; Cookie:string = ''; param:string = ''; grabCookie:Boolean = False):string;stdcall;
var
s:string;
sg:Boolean;
begin
sg:=True;
http.Create(Url, param, Cookie, @s, grabCookie, @sg);
while sg do
Sleep(5);
result:=s;
end;function HugUrl(Url:string; Cookie:string = ''; param:string = ''; grabCookie:Boolean = False):string;stdcall;
var
pd:TStrings;
s:string;
sg:Boolean;
i:Integer;
begin
pd := TStringList.Create;
pd.Text := param;
Url := Url + '?';
sg:=True;
for i := 0 to pd.Count - 1 do
begin
Url := Url + pd.Strings[i] + '&';
end;
http.Create(Url, '', Cookie, @s, grabCookie, @sg);
while sg do
Sleep(5);
pd.Destroy;
result:=s;
end;exports
TouchUrl,
HugUrl;begin
end.
unit wTouch;interfaceuses Classes, IdSocks, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, Windows;type
pstr = ^string;type
wSign = ^Boolean;type
http = class(TThread)
private
web: TIdHTTP;
aurl:string;
apdt:string;
acookie:string;
jsondt:pstr;
ssign:wSign;
grabCookie:Boolean;
protected
procedure Execute; override;
public
constructor Create(url:string; pdt:string; cookies:string; rejson : pstr; gcookie:Boolean; sign:wSign);
end;implementationprocedure http.Execute;
var
Response:TStringStream;
pd:TStrings;
begin
web:=TIdHTTP.Create(nil);
pd:=TStringList.Create;
pd.Text:=apdt;
web.HandleRedirects:=true;
web.Request.CustomHeaders.Add('Cookie:'+acookie);
Response:=TStringStream.Create('');
try
web.Post(aurl, pd, Response);
jsondt^:= Response.DataString;
except
jsondt^:='{"Status":"0099"}';
end;
ssign^:=False;
web.Destroy;
pd.Destroy;
Response.Destroy;
end;constructor http.Create(url:string; pdt:string; cookies:string; rejson : pstr; gcookie:Boolean; sign:wSign);
begin
aurl:=url;
apdt:=pdt;
jsondt:=rejson;
ssign:=sign;
acookie:=cookies;
grabCookie:=gcookie;
FreeOnTerminate:=True;
Inherited Create(False);
end;end.
uses
SysUtils,
Classes,
wTouch in 'wTouch.pas';{$R *.res}function TouchUrl(Url:string; Cookie:string = ''; param:string = ''; grabCookie:Boolean = False):string;stdcall;
var
s:string;
sg:Boolean;
begin
sg:=True;
http.Create(Url, param, Cookie, @s, grabCookie, @sg);
while sg do
Sleep(5);
result:=s;
end;function HugUrl(Url:string; Cookie:string = ''; param:string = ''; grabCookie:Boolean = False):string;stdcall;
var
pd:TStrings;
s:string;
sg:Boolean;
i:Integer;
begin
pd := TStringList.Create;
pd.Text := param;
Url := Url + '?';
sg:=True;
for i := 0 to pd.Count - 1 do
begin
Url := Url + pd.Strings[i] + '&';
end;
http.Create(Url, '', Cookie, @s, grabCookie, @sg);
while sg do
Sleep(5);
pd.Destroy;
result:=s;
end;exports
TouchUrl,
HugUrl;begin
end.
unit wTouch;interfaceuses Classes, IdSocks, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, Windows;type
pstr = ^string;type
wSign = ^Boolean;type
http = class(TThread)
private
web: TIdHTTP;
aurl:string;
apdt:string;
acookie:string;
jsondt:pstr;
ssign:wSign;
grabCookie:Boolean;
protected
procedure Execute; override;
public
constructor Create(url:string; pdt:string; cookies:string; rejson : pstr; gcookie:Boolean; sign:wSign);
end;implementationprocedure http.Execute;
var
Response:TStringStream;
pd:TStrings;
begin
web:=TIdHTTP.Create(nil);
pd:=TStringList.Create;
pd.Text:=apdt;
web.HandleRedirects:=true;
web.Request.CustomHeaders.Add('Cookie:'+acookie);
Response:=TStringStream.Create('');
try
web.Post(aurl, pd, Response);
jsondt^:= Response.DataString;
except
jsondt^:='{"Status":"0099"}';
end;
ssign^:=False;
web.Destroy;
pd.Destroy;
Response.Destroy;
end;constructor http.Create(url:string; pdt:string; cookies:string; rejson : pstr; gcookie:Boolean; sign:wSign);
begin
aurl:=url;
apdt:=pdt;
jsondt:=rejson;
ssign:=sign;
acookie:=cookies;
grabCookie:=gcookie;
FreeOnTerminate:=True;
Inherited Create(False);
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货