Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Apr : How to stop IdHTTP GET and POST?
| Subject: | How to stop IdHTTP GET and POST? |
| Posted by: | "Samson Fu" (fusams..@gmail.com) |
| Date: | Thu, 14 Apr 2005 14:47:07 |
I have a Thread to run GET/POST of a TIdHTTP. I use thread because I don't want GET/POST to blocking main thread.
But how to stop the GET/POST from main Thread? I tried to disconnect the IdHTTP in main thread, but exception box appear.
Here is the Thread I implemented for HTTP GET and POST:
Type
THttpAction = (haGet, haPost);
THTTPActionThread = class(TThread)
private
_Action:THttpAction;
_HTTP:TIdHTTP;
_URL:String;
_Stream:TStream;
protected
procedure Execute; override;
public
constructor Create(AAction:THttpAction; AHTTP:TIdHTTP; const AURL:String; AStream:TStream);
end;
{ THTTPActionThread }
constructor THTTPActionThread.Create(AAction: THttpAction; AHTTP: TIdHTTP;
const AURL: String; AStream: TStream);
begin
_Action:=AAction;
_HTTP:=AHTTP;
_URL:=AURL;
_Stream:=AStream;
FreeOnTerminate:= True;
Inherited Create(False);
end;
procedure THTTPActionThread.Execute;
begin
If Assigned(_HTTP) and Assigned(_Stream) then
try
try
Case _Action of
haGet: _HTTP.Get(_URL, _Stream);
haPost: _HTTP.Post(_URL, _Stream);
End;
finally
_Stream.Free;
end;
except
end;
end;
//Thanks!
--
Samson Fu