DownloadURL

DownloadURL function

Retrieves a file from an internet URL into a Stream.


function DownloadURL(Const URL: String; Const ToStream: TStream; OnCallback: TDownloadURLCallBack; UseCache: Boolean): HResult;

Unit
TeeURL

Description
This function can be used to retrieve a file from a remote URL (internet address).
Returns 0 when succesful, otherwise returns an error code.

Under Windows, this function uses the Microsoft WinInet DLL.
Uses CLX and Linux, the Indy HTTP component is used.

Note: When requesting an invalid non-existent URL file, the function will return 0 (ok), but the content in the Stream will contain an html "404" error from the web server.

See also the TeeURLErrorMessage function.

Example:

Uses TeeURL;

procedure TForm1.Button1Click(Sender: TObject);
Var MyStream : TMemoryStream;
ErrorCode : HResult;
begin
MyStream := TMemoryStream.Create;
try
ErrorCode:= DownloadURL('http://www.steema.com/demo.txt',MyStream);
if ErrorCode=0 then
Memo1.Lines.LoadFromStream(MyStream)
else
ShowMessage( TeeURLErrorMessage( ErrorCode ) );
finally
MyStream.Free;
end;
end;