Hi all.
I followed the excellent example source (HttpAsy1). It works well. I filled a
CheckListBox with remote files to catch. If one file fails (StatusCode = 404) I
change the file extension and do another request. The OnRequestDone is only
assigned if the StatusCode is <> 404. That works well, but the resulting file
has no content.
I want to download several zipped files. But if one zip file is not there, I
try to download a text file (thats the unzipped file on the server).
I give the example code:
procedure TForm1.ExecSimultaneous;
begin
for Item := 1 to CheckListBox1.Items.Count do begin
AHttpCli := THttpCli.Create(Self);
with AHttpCli do begin
MultiThreaded := True;
FHttpCliList.Add(AHttpCli);
Tag := Item;
URL := Trim(CheckListBox1.Items[Item-1]);
RcvdStream := TMemoryStream.Create;
AHttpCli.OnHeaderData := HttpCli1HeaderData;
AHttpCli.GetAsync
end
end
end;
procedure TForm1.HttpCli1HeaderData(Sender: TObject);
begin
with THttpCli(Sender) do begin
if StatusCode = 404 then begin
Abort;
URL := ChangeFileExt(URL, '.txt');
GetAsync;
Exit
end;
OnRequestDone := HttpCliItemRequestDone
end
end;
procedure TForm1.HttpCliItemRequestDone(
Sender : TObject;
RqType : THttpRequest;
Error : Word);
var
Item : Integer;
AHttpCli : THttpCli;
Count : Integer;
SL: TMemoryStream;
s: String;
begin
AHttpCli := Sender as THttpCli;
{ Remove the item form the list }
Count := FHttpCliList.Count;
for Item := 1 to Count do begin
if AHttpCli = FHttpCliList.Items[Item - 1] then begin
SL := TMemoryStream.Create;
SL.LoadFromStream(AHttpCli.RcvdStream);
SL.SaveToFile('c:\' + Copy(s, LastDelimiter('/', s) + 1, 999));
SL.Free;
AHttpCli.RcvdStream.Free;
FHttpCliList.Delete(Item - 1);
Break
end
end;
{ Free the item }
AHttpCli.Free;
end;
Hope, that someone can help me or can show me a better way.
Thanks, Christian
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be