Skip to content

Instantly share code, notes, and snippets.

@andreiverse
Created September 14, 2022 13:48
Show Gist options
  • Select an option

  • Save andreiverse/f22367b5cfcf5cf48a1fd604e30f9ada to your computer and use it in GitHub Desktop.

Select an option

Save andreiverse/f22367b5cfcf5cf48a1fd604e30f9ada to your computer and use it in GitHub Desktop.
wininet get requests
#define _UNICODE
#include <tchar.h>
#include <wchar.h>
#include <Windows.h>
#include <WinInet.h>
#include <stdio.h>
int http_getrequest(char * host, int port, char * path, DWORD dwFileSize, DWORD * dwBytesRead, char * buffer) {
HINTERNET hSession = InternetOpen(
"Mozilla/5.0",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0
);
HINTERNET hConnect = InternetConnect(
hSession,
host,
port, "", "",
INTERNET_SERVICE_HTTP,
0, 0
);
HINTERNET hHttpFile = HttpOpenRequest(
hConnect,
"GET",
path,
NULL, NULL, NULL, 0, 0
);
while (!HttpSendRequest(hHttpFile, NULL, 0, 0, 0)) {
printf("HttpSendRequest Error: (%lu)\n", GetLastError());
}
BOOL bRead;
bRead = InternetReadFile(
hHttpFile,
buffer,
dwFileSize + 1,
dwBytesRead
);
if (!bRead) {
printf("InternetReadFile Error: (%lu)", GetLastError());
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment