I'm new to C++, I am trying to consume the ip-api.com
API to fetch a geolocation based on an IP number. But I can't make a request correctly. What can I change in this code to get the JSON response correctly?
string GetLocation() {
DWORD size = 0;
DWORD wrt;
LPCWSTR down = L"Downloader";
string msg = "";
/*wstring ipConvert(ipAdr().begin(), ipAdr().end());
LPCWSTR ip = ipConvert.c_str();*/
string url = "http://ip-api.com/json/168.197.155.244";
wstring urlConvert(url.begin(), url.end());
LPCWSTR urlFinal = L"http://ip-api.com/json/168.197.155.244";
LPCWSTR headers = L"Content-Type: application/json\r\n";
HINTERNET open = InternetOpen(down, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
HINTERNET connect = InternetConnect(open, urlFinal, NULL, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
HINTERNET request = HttpOpenRequest(connect, NULL, urlFinal, NULL, NULL, 0, 0, 0);
HttpAddRequestHeaders(request, headers, -1, HTTP_ADDREQ_FLAG_ADD);
HttpSendRequest(request, NULL, 0, NULL, 0);
InternetQueryDataAvailable(request, &size, 0, 0);
char* buff = new char[size + 1];
memset(buff, 0, size + 1);
InternetReadFile(request, buff, size, &wrt);
msg += buff;
InternetCloseHandle(open);
InternetCloseHandle(connect);
InternetCloseHandle(request);
return msg;
}