i'm trying to download file from http server using WinINet library calls. It works perfectly fine on my local web server. but when i'm trying download something from the internet, InternetReadFile reads only ~10kb of any file (text or binary). TRANSFER_SIZE = 4096 in the example below, thus there are two reads by 4kb and one by 2kb. Every next InternetReadFile returns true and 0 bytes read.
hInternet = InternetOpen(L"Agent", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
DWORD options = INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_HYPERLINK|INTERNET_FLAG_RESYNCHRONIZE|INTERNET_FLAG_RELOAD;
HINTERNET hSession = InternetOpenUrl(hInternet, URL, NULL, NULL, options, 0);
hFile = CreateFile(...);
...
do {
DWORD dwWriteSize, dwNumWritten;
BOOL bRead = InternetReadFile(hSession, pBuf, TRANSFER_SIZE, &dwReadSizeOut);
dwWriteSize = dwReadSizeOut;
if (bRead && dwReadSizeOut > 0) {
dwTotalReadSize += dwReadSizeOut;
WriteFile(hFile, pBuf, dwWriteSize, &dwNumWritten, NULL);
// File write error
if (dwWriteSize != dwNumWritten) {
CloseHandle(hFile);
return false;
}
}
else {
if (!bRead)
{
// Error
CloseHandle(hFile);
return false;
}
break;
}
} while(1);
How can i download the entire file using WinINet library?