#include <windows.h>
#include <wininet.h>
#pragma comment(lib,"wininet.lib")
#include <string>
using namespace std;
string GetPage(LPCSTR server, LPCSTR path)
{
DWORD dwRead;
HINTERNET hSession = InternetOpen("GetPage/1.0",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
HINTERNET hConnection = InternetConnect(hSession,server,INTERNET_DEFAULT_HTTP_PORT,"","",INTERNET_SERVICE_HTTP,0,0);
if(!hConnection)
{
MessageBox(NULL,"An error occured while trying to connect to the host specified.",NULL,MB_OK);
SetLastError(ERROR_CONNECTION_INVALID);
return "Error opening site";
}
HINTERNET hData = HttpOpenRequest(hConnection,"GET",path,NULL,NULL,NULL,INTERNET_FLAG_KEEP_CONNECTION,0);
HttpSendRequest(hData,NULL,0,NULL,0);
CHAR pageContents[2048];
string retVal;
while(InternetReadFile(hData,pageContents,255,&dwRead))
{
if(dwRead==0)
{
break;
}
pageContents[dwRead]=0;
retVal+=pageContents;
}
InternetCloseHandle(hConnection);
InternetCloseHandle(hSession);
return retVal;
}