I am trying to fetch my server html text data using wininet, but it seems to be reading it and breaking it into 513 byte size chunks. However I would prefer the data to be fetched as a whole. Is there a way I can go around this?
Here is a full code for references:
#include <windows.h>
#include <wininet.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#pragma comment (lib, "Wininet.lib")
int main(int argc, char** argv) {
HINTERNET hSession = InternetOpen(L"Mozilla/5.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hSession, L"www.google.com", 0, L"", L"", INTERNET_SERVICE_HTTP, 0, 0);
HINTERNET hHttpFile = HttpOpenRequest(hConnect, L"GET", L"/", NULL, NULL, NULL, 0, 0);
while (!HttpSendRequest(hHttpFile, NULL, 0, 0, 0)) {
printf("Server Down.. (%lu)\n", GetLastError());
InternetErrorDlg(GetDesktopWindow(), hHttpFile, ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED, FLAGS_ERROR_UI_FILTER_FOR_ERRORS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL);
}
DWORD dwFileSize;
dwFileSize = BUFSIZ;
char* buffer;
buffer = new char[dwFileSize + 1];
while (true) {
DWORD dwBytesRead;
BOOL bRead;
bRead = InternetReadFile(hHttpFile, buffer, dwFileSize + 1, &dwBytesRead);
if (dwBytesRead == 0) break;
if (!bRead) {
printf("InternetReadFile error : <%lu>\n", GetLastError());
}
else {
buffer[dwBytesRead] = 0;
std::string newbuff = buffer;
std::wcout << "\n\nSize: " << newbuff.size() << std::endl;
std::cout << newbuff;
}
}
InternetCloseHandle(hHttpFile);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
}