Using this code in Delphi for getting a web page size: (I mean page source size)
uses
IdHTTP
function URLsize(const URL : string) : integer;
var
Http: TIdHTTP;
begin
Http := TIdHTTP.Create(nil);
try
Http.Head(URL);
result := round(Http.Response.ContentLength / 1048576); //MB
finally
Http.Free;
end;
end;
I can get file size easily for some URLs like http://sample.com/test.exe
. It returns the size in MB.
But I cannot get URL size using this code for a URL like http://stackoverflow.com/
; it returns 0
or -1
.
How can I get the size in that case?