Skip to content

Instantly share code, notes, and snippets.

@zah
Created July 31, 2014 13:11
Show Gist options
  • Select an option

  • Save zah/0996c3825a5ee4e9b697 to your computer and use it in GitHub Desktop.

Select an option

Save zah/0996c3825a5ee4e9b697 to your computer and use it in GitHub Desktop.
int MakeGetRequest(const TCHAR* server, const TCHAR* url, string& out)
{
auto inet = InternetOpen(_T("AdRotate"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, 0, 0);
if(inet == NULL)
return 1;
auto session = InternetConnect(inet, server, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL);
if(session == NULL)
return 2;
PCTSTR acceptedTypes[] = {_T("*"), NULL};
auto request = HttpOpenRequest(session, _T("GET"), url, _T("HTTP/1.0"), NULL, acceptedTypes, 0, NULL);
if(request == NULL)
return 3;
if(HttpSendRequestEx(request, NULL, 0, NULL, 0) != TRUE)
return 4;
if(HttpEndRequest(request, NULL, 0, 0) != TRUE)
return 5;
DWORD content_length;
if(InternetQueryDataAvailable(request, &content_length, 0, 0) != TRUE)
return 6;
string data;
data.resize(content_length);
DWORD bytes_read;
if(InternetReadFile(request, &data[0], content_length, &bytes_read) != TRUE)
return 7;
out.swap(data);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment