Created
September 14, 2022 13:48
-
-
Save andreiverse/f22367b5cfcf5cf48a1fd604e30f9ada to your computer and use it in GitHub Desktop.
wininet get requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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