Gallery
Software
Music
Programming
Archive
Tuesday, May 21 Week 21
Customize the parameters for timeout and redirects.
It returns the destination URL when navigating is done.

uses
idHttp;

const
INET_USERAGENT = 'Mozilla/4.0, Indy Library (Windows; en-US)';
INET_TIMEOUT_SECS = 3;
INET_REDIRECT_MAX = 10;

function downloadSrc(var aUrl:ansiString):ansiString;
begin
with tIdHttp.create(nil) do begin //Create Indy http object
request.userAgent:=INET_USERAGENT; //Custom user agent string
redirectMaximum:=INET_REDIRECT_MAX; //Maximum redirects
handleRedirects:=INET_REDIRECT_MAX0; //Handle redirects
readTimeOut:=INET_TIMEOUT_SECS*1000; //Read timeout msec
try //Catch errors
result:=get(aUrl); //Do the request
if url.port='80' then url.port:=''; //Remove port 80 from final URL
aUrl:=url.getFullURI //Return final URL
except result:='error' end; //Return an error message if failed
free //Free the http object
end
end;

Example

procedure TForm1.FormCreate(Sender: TObject);
var s:ansiString;
begin
s:='http://www.mortenbs.com/';
memo1.lines.text:=downloadSrc(s);
caption:='URL: '+s
end;

Related pages of Download HTML-source using Indy HTTP

Download file using Indy HTTP
Delphi programming
Programming
Delphi examples
Remove HTML from text
Valid IP address syntax
Convert between IPv4 and string
DNS Lookup, IP and host name