var
hOpen, hConnect, hResource: HINTERNET;
//Hier der Link auf die Amazon Seite: "Guns n Roses - Chinese Democracy"
Host:String='
www.amazon.de';
Resource:String='
/s/ref=nb_ss_w?__mk_de_DE=%C5M%C5Z%D5%D1&url=search-alias%3Daps&field-keywords=chinese&x=0&y=0';
function DownloadAtPos(
const AURL, AFileName:
string; APos: Integer): Integer;
var
FileStream: TFileStream;
s:
string;
DataProceed:
array[0..8191]
of Byte;
numread: DWORD;
begin
hOpen := InternetOpen('
WinInet sample', INTERNET_OPEN_TYPE_PRECONFIG,
nil,
nil, 0);
hConnect := InternetConnect(hOpen, PChar(host), INTERNET_DEFAULT_HTTP_PORT,
nil,
nil, INTERNET_SERVICE_HTTP, 0, 0);
hResource := HttpOpenRequest(hConnect, '
GET', PChar(resource),
nil,
nil,
nil, 0, 0);
s := Format('
Range: bytes=%d-%d', [100000,150000]);
//Setze den zu lesenden Bereich
HttpAddRequestHeaders(hResource, PChar(s), Length(s), HTTP_ADDREQ_FLAG_ADD_IF_NEW);
//schreibe Header
HttpSendRequest(hResource,
nil, 0,
nil, 0);
//Download der Datei
FileStream := TFileStream.Create(AFileName, fmCreate);
try
FileStream.Size:=0;
FileStream.Position := 0;
repeat
ZeroMemory(@DataProceed, SizeOf(DataProceed));
InternetReadFile(hResource, @DataProceed, SizeOf(DataProceed), numread);
if (numread <= 0)
then Break;
FileStream.
Write(DataProceed, numread);
Result := Result + Integer(numread);
until (
not FIsDownloading);
finally
FileStream.Free();
InternetCloseHandle(hConnect);
InternetCloseHandle(hOpen);
end;
end;
function GetResourceSize(
const AURL:
string): Integer;
var
s:
string;
buflen, tmp: DWORD;
begin
hOpen := InternetOpen('
WinInet resuming sample', INTERNET_OPEN_TYPE_PRECONFIG,
nil,
nil, 0);
hConnect := InternetConnect(hOpen, PChar(host), INTERNET_DEFAULT_HTTP_PORT,
nil,
nil, INTERNET_SERVICE_HTTP, 0, 0);
hResource := HttpOpenRequest(hConnect, '
HEAD', PChar(resource),
nil,
nil,
nil, 0, 0);
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(hConnect);
InternetCloseHandle(hOpen);
end;