#include <iostream>
#include <string.h>
#include <winsock2.h>
#include "Wininet.h"
#pragma comment (lib,"Wininet.lib")
char * GetHtml(char *domain,char *url)
{
char buff[1024]={0};
char frmdata[256]={0};
char *lpData=NULL;
int tmplen=0;
sprintf(frmdata,"%s",url);
HINTERNET hSession = InternetOpen("check icp",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hSession)
{
HINTERNET hConnect = InternetConnect(hSession, domain,INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if (hConnect)
{
HINTERNET hRequest = ::HttpOpenRequest(hConnect, "GET ", frmdata, HTTP_VERSION, NULL, 0, INTERNET_FLAG_DONT_CACHE, 1);
if(hRequest)
{
if(HttpSendRequest(hRequest, NULL, 0, 0, 0))
{
// Get the length of the file.
char bufQuery[32] ;
DWORD dwLengthBufQuery = sizeof(bufQuery);
BOOL bQuery = ::HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH, bufQuery, &dwLengthBufQuery,NULL) ;
int lQuery=atoi(bufQuery)+10;
lpData=(char *)malloc(lQuery);
if(lpData)
{
memset(lpData,0,lQuery);
DWORD dwData=0;
DWORD dwBuff=0;
DWORD dwRead=0;
while (InternetReadFile(hRequest, buff, 1024, &dwRead) && dwRead>0)
{
if((tmplen+dwRead)<lQuery)
{
memcpy(&lpData[tmplen],buff,dwRead);
}
tmplen=tmplen+dwRead;
}
printf("%s/n",lpData);
free(lpData);
}
}
InternetCloseHandle(hRequest);
}
InternetCloseHandle(hConnect);
}
InternetCloseHandle(hSession);
}
return NULL;
}