summaryrefslogtreecommitdiff
path: root/src/windows/platform.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik.ramaekers@protonmail.com>2020-02-16 11:44:55 +0100
committerAldrik Ramaekers <aldrik.ramaekers@protonmail.com>2020-02-16 11:44:55 +0100
commit138b63df9af0f32c0e22172dddf5234759883f67 (patch)
tree8e039dadc90ef091ade671d0eeed0cd3ac00b942 /src/windows/platform.c
parentb0c2f39e24cd6e09db23258e172e4390e72d0dca (diff)
licensing
Diffstat (limited to 'src/windows/platform.c')
-rw-r--r--src/windows/platform.c49
1 files changed, 49 insertions, 0 deletions
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 <wininet.h>
#include <locale.h>
#include <windows.h>
#include <GL/gl.h>
@@ -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