nikola_mk
asked on
Wininet downloading file .When I start with downloading my project is blocked (freezed).
I use Wininet lib. for downloading file from internet. When I start with downloading my project is blocked (freezed).
How can i fix this problem?
I use this method for downloading file:
{
var
hInternetO,hHInternetC,hRe source:HIN TERNET;
FileStream:TFileStream;
DataProceed:array[0..1023] of Char;
NumRead,i:Cardinal;
kraj:Boolean;
begin
hInternetO:=InternetOpen( 'Naslov',INTERNET_OPEN_TYP E_PRECONFI G,nil,nil, 0 );
hHInternetC:=InternetConne ct( HInternetO,PAnsiChar(Host) ,INTERNET_ DEFAULT_HT TP_PORT,ni l,nil,INTE RNET_SERVI CE_HTTP,0, 0);
hResource := HttpOpenRequest(hHInternet C, 'GET', PChar(Resource), nil, nil, nil, 0, 0);
HttpSendRequest(hResource, nil, 0, nil, 0);
///
try
FileStream := TFileStream.Create('c:\', FileOpenModes[FileExists(' c:\')]);
except
ShowMessage('Please enter valid URL !');
Exit;
end;
try
FileStream.Position := Result;
repeat
ZeroMemory(@DataProceed, SizeOf(DataProceed));
InternetReadFile(hResource , @DataProceed, SizeOf(DataProceed)-1, NumRead);
if (NumRead <= 0) then Break;
FileStream.Write(DataProce ed, NumRead);
Result := Result + Integer(NumRead);
until Kraj=true;
finally
FileStream.Free();
InternetCloseHandle(hHInte rnetC);
InternetCloseHandle(hInter netO);
end;
}
Thank you.
How can i fix this problem?
I use this method for downloading file:
{
var
hInternetO,hHInternetC,hRe
FileStream:TFileStream;
DataProceed:array[0..1023]
NumRead,i:Cardinal;
kraj:Boolean;
begin
hInternetO:=InternetOpen( 'Naslov',INTERNET_OPEN_TYP
hHInternetC:=InternetConne
hResource := HttpOpenRequest(hHInternet
HttpSendRequest(hResource,
///
try
FileStream := TFileStream.Create('c:\', FileOpenModes[FileExists('
except
ShowMessage('Please enter valid URL !');
Exit;
end;
try
FileStream.Position := Result;
repeat
ZeroMemory(@DataProceed, SizeOf(DataProceed));
InternetReadFile(hResource
if (NumRead <= 0) then Break;
FileStream.Write(DataProce
Result := Result + Integer(NumRead);
until Kraj=true;
finally
FileStream.Free();
InternetCloseHandle(hHInte
InternetCloseHandle(hInter
end;
}
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.