From 138b63df9af0f32c0e22172dddf5234759883f67 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sun, 16 Feb 2020 11:44:55 +0100 Subject: licensing --- src/windows/platform.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/windows/platform.c') diff --git a/src/windows/platform.c b/src/windows/platform.c index dd7b97f..2172fd5 100644 --- a/src/windows/platform.c +++ b/src/windows/platform.c @@ -4,6 +4,7 @@ * All rights reserved. */ +#include #include #include #include @@ -1270,4 +1271,52 @@ s16 string_to_s16(char *str) s8 string_to_s8(char *str) { return (s8)strtoul(str, 0, 10); +} + +bool platform_send_http_request(char *url, char *params, char *response_buffer) +{ + // https://www.unix.com/programming/187337-c-http-get-request-using-sockets.html + + bool response = true; + HINTERNET hIntSession = 0; + HINTERNET hHttpSession = 0; + HINTERNET hHttpRequest = 0; + + hIntSession = InternetOpen("Text-Search", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); + if (!hIntSession) goto failure; + + hHttpSession = InternetConnect(hIntSession, url, 80, 0, 0, INTERNET_SERVICE_HTTP, 0, 0); + if (!hHttpSession) goto failure; + + hHttpRequest = HttpOpenRequest( + hHttpSession, + "GET", + params, + 0, 0, 0, INTERNET_FLAG_RELOAD, 0); + + + char* szHeaders = "Content-Type: application/json"; + char szReq[1024] = ""; + if(!HttpSendRequest(hHttpRequest, szHeaders, strlen(szHeaders), szReq, strlen(szReq))) { + goto failure; + } + + DWORD dwRead=0; + while(InternetReadFile(hHttpRequest, response_buffer, MAX_INPUT_LENGTH-1, &dwRead) && dwRead) { + response_buffer[dwRead] = 0; + dwRead=0; + } + + goto done; + + failure: + printf("failure"); + response = false; + + done: + InternetCloseHandle(hHttpRequest); + InternetCloseHandle(hHttpSession); + InternetCloseHandle(hIntSession); + + return response; } \ No newline at end of file -- cgit v1.2.3-70-g09d2