#include <stdio.h>
#include <Windows.h>
#include <winhttp.h>
#pragma comment (lib, "winhttp.lib")
int main() {
DWORD dwSize = 0, dwDownloaded;
LPSTR source;
HINTERNET
hSession = NULL,
hConnect = NULL,
hRequest = NULL;
BOOL bResults = FALSE;
hSession = WinHttpOpen(L"Winhttp API", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
if (hSession)
hConnect = WinHttpConnect(hSession, L"255.255.255.255", INTERNET_DEFAULT_HTTP_PORT, 0);
if (hConnect)
hRequest = WinHttpOpenRequest(hConnect, L"GET", L"/set_data.php?coordinate_x=123&coordinate_y=11", NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
if (hRequest)
bResults = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
if (bResults)
bResults = WinHttpReceiveResponse(hRequest, NULL);
if (bResults) {
do {
dwSize = 0;
if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
printf("Error %u in WinHttpQueryDataAvailable.\n", GetLastError());
source = (char *)malloc(dwSize + 1);
if (!source) {
printf("Out of memory\n");
dwSize = 0;
} else {
ZeroMemory(source, dwSize + 1);
if (!WinHttpReadData(hRequest, (LPVOID)source, dwSize, &dwDownloaded))
printf("Error %u in WinHttpReadData.\n", GetLastError());
else
printf("%s\n", source);
free(source);
}
}while (dwSize > 0);
}
if (!bResults)
printf("Error %d has occurred.\n", GetLastError());
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);
return 0;
}