Скачиваю файл через WinINet, 70 байт. С моего сайта скачивается нормально, а с гугловского бесплатного сайта — через раз!
Я знаю, что бесплатные хостинги говно, но чтобы настолько...
Файл такой:
https://sites.google.com/site/lvbdinfo/version-txt/version.txt
Код такой:
struct DownloadResult {
bool success;
std::string content;
};
DownloadResult DownloadFile(const std::string& url)
{
HINTERNET hSession = InternetOpen("Mozilla/5.0", INTERNET_OPEN_TYPE_PRECONFIG,
nullptr, nullptr, 0);
if (!hSession)
return DownloadFailure;
unique_hinternet sessionClosing(hSession, &InternetCloseHandle);
const DWORD flags = INTERNET_FLAG_IGNORE_CERT_CN_INVALID |
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_NO_COOKIES |
INTERNET_FLAG_NO_UI |
INTERNET_FLAG_RELOAD; // INTERNET_FLAG_SECURE?
const HINTERNET hFile = InternetOpenUrlA(hSession, url.c_str(), nullptr, 0, flags, 0);
if (!hFile)
return DownloadFailure;
unique_hinternet fileClosing(hFile, &InternetCloseHandle);
std::string result;
DWORD bytesRead;
do {
char buffer[10240];
const BOOL success = InternetReadFile(hFile, buffer, sizeof(buffer), &bytesRead);
if (!success)
return DownloadFailure;
result.append(buffer, buffer + bytesRead);
} while (bytesRead != 0);
return {true, result};
}
Что криво?
P.S. Гугл внезапно снес мой файл, и не дает его загрузить обратно на сайт. Странно.