Registriert seit: 7. Jun 2003
Ort: Mülheim an der Ruhr
435 Beiträge
Delphi 10.3 Rio
|
Re: Idhttp wie an den Dateinamen kommen ?
14. Apr 2010, 08:51
Die Rückgabe vom Header parsen...?!
Experts Exchange
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
MemStream: TMemoryStream;
FileStream: TFileStream;
begin
MemStream := TMemoryStream.Create;
try
IdHTTP1.Get('http://www.deadlybossmods.com/download.php?id=1', MemStream);
MemStream.Position := 0;
FileStream := TFileStream.Create(FileName, fmCreate);
try
MemStream.SaveToStream(FileStream);
finally
FileStream.Free;
end;
finally
MemStream.Free;
end;
end;
procedure TForm1.IdHTTP1HeadersAvailable(Sender: TObject;
AHeaders: TIdHeaderList; var VContinue: Boolean);
var
ContentDisposition: string;
begin
ContentDisposition := AHeaders.Values['Content-Disposition'];
ContentDisposition := Copy(ContentDisposition, 1 + Pos(';', ContentDisposition), MaxInt);
ContentDisposition := StringReplace(ContentDisposition, 'filename=', '', [rfIgnoreCase]);
ContentDisposition := StringReplace(ContentDisposition, '"', '', [rfReplaceAll]);
FileName := ContentDisposition;
end;
end.
|
|
Zitat
|