nikola_mk
asked on
Geting file size using wininet?
Hi I use wininet library for downloading file from net.I use this function for getting file size, but this function not work properly don't give me results(return 0) for any URL (valid URL) especially on bigger files.What is problem with bigger files??or how to detect redirect?
nn ex.
http://download2.gamespot.com/d4/gsc/action/fearcombat/fearcombat_en_107.exe (return 0)
http://us.rd.yahoo.com/games/buzz/downloads/486514/SIG=1344l74qj/*http%3A//h.yimg.com/download2.games.yahoo.com/games/buzz2/
content/p/0/486514/parawor ld_sp_demo .exe (return 1.3GB)
Please give me some idea or function for this
function TMainForm.GetResourceSize( const AURL: string): Integer;
var
hOpen, hConnect, hResource: HINTERNET;
host, resource: string;
buflen, tmp: Cardinal;
begin
ParseURL(AURL, host, resource);
hOpen := InternetOpen('WinInet resuming sample', INTERNET_OPEN_TYPE_PRECONF IG, nil, nil, 0);
if Assigned(hOpen) then edtFile.Text:=edtFile.Text +' 1 OK ' else edtFile.Text:=edtFile.Text +' 1 NO ';
hConnect := InternetConnect(hOpen, PChar(host), INTERNET_DEFAULT_HTTP_PORT , nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
if Assigned(hConnect) then edtFile.Text:=edtFile.Text +' 2 OK ' else edtFile.Text:=edtFile.Text +' 2 NO ';
hResource := HttpOpenRequest(hConnect, 'HEAD', PChar(resource), nil, nil, nil, 0, 0);
if Assigned(hResource) then edtFile.Text:=edtFile.Text +' 3 OK ' else edtFile.Text:=edtFile.Text +' 3 NO ';
HttpSendRequest(hResource, nil, 0, nil, 0);
buflen := SizeOf(Result);
tmp := 0;
Result := 0;
HttpQueryInfo(hResource, HTTP_QUERY_CONTENT_LENGTH or HTTP_QUERY_FLAG_NUMBER,
@Result, buflen, tmp);
InternetCloseHandle(hConne ct);
InternetCloseHandle(hOpen) ;
end;
Regards, Nikola
nn ex.
http://download2.gamespot.com/d4/gsc/action/fearcombat/fearcombat_en_107.exe (return 0)
http://us.rd.yahoo.com/games/buzz/downloads/486514/SIG=1344l74qj/*http%3A//h.yimg.com/download2.games.yahoo.com/games/buzz2/
content/p/0/486514/parawor
Please give me some idea or function for this
function TMainForm.GetResourceSize(
var
hOpen, hConnect, hResource: HINTERNET;
host, resource: string;
buflen, tmp: Cardinal;
begin
ParseURL(AURL, host, resource);
hOpen := InternetOpen('WinInet resuming sample', INTERNET_OPEN_TYPE_PRECONF
if Assigned(hOpen) then edtFile.Text:=edtFile.Text
hConnect := InternetConnect(hOpen, PChar(host), INTERNET_DEFAULT_HTTP_PORT
if Assigned(hConnect) then edtFile.Text:=edtFile.Text
hResource := HttpOpenRequest(hConnect, 'HEAD', PChar(resource), nil, nil, nil, 0, 0);
if Assigned(hResource) then edtFile.Text:=edtFile.Text
HttpSendRequest(hResource,
buflen := SizeOf(Result);
tmp := 0;
Result := 0;
HttpQueryInfo(hResource, HTTP_QUERY_CONTENT_LENGTH or HTTP_QUERY_FLAG_NUMBER,
@Result, buflen, tmp);
InternetCloseHandle(hConne
InternetCloseHandle(hOpen)
end;
Regards, Nikola
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.