#include
#include
#include
void split_url(char* url,char* host,char* file);
int main(int argc, char* argv[])
{
char url[] = "http:;
HINTERNET hInet;
HINTERNET hConn;
HINTERNET hReq;
char szBuf[1024],host[256],file[256];
DWORD dwSize;
DWORD dwIndex;
bool bret;
memset(host,0,sizeof(char)*256);
memset(file,0,sizeof(char)*256);
split_url(url,host,file);
hInet = ::InternetOpen("simple http request",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,NULL,0);
if( hInet == NULL) {
return -1;
}
hConn = ::InternetConnect( hInet,
host,
INTERNET_default_HTTP_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0, NULL);
if( hConn == NULL) {
::InternetCloseHandle( hInet);
return -1;
}
hReq = ::HttpOpenRequest( hConn,
"GET",
file,
NULL,
NULL,
NULL,
0, NULL);
if( hReq == NULL) {
::InternetCloseHandle( hConn);
::InternetCloseHandle( hInet);
return -1;
}
if( ::HttpSendRequest( hReq, NULL, 0, NULL, 0) != true) {
::InternetCloseHandle( hReq);
::InternetCloseHandle( hConn);
::InternetCloseHandle( hInet);
return -1;
}
bret = true;
dwIndex = 0;
while( bret == true) {
dwSize = sizeof(szBuf) - 1;
memset(szBuf,0x00,sizeof(szBuf));
bret = ::HttpQueryInfo( hReq,
HTTP_QUERY_RAW_HEADERS_CRLF |
HTTP_QUERY_FLAG_NUMBER,
szBuf, &dwSize, &dwIndex);
dwIndex++;
printf(szBuf);
}
bret = true;
while( bret == true) {
dwSize = 0;
memset(szBuf,0x00,sizeof(szBuf));
bret = ::InternetReadFile( hReq, szBuf, sizeof( szBuf) - 1, &dwSize);
printf(szBuf);
if(dwSize == 0) {
break;
}
}
::InternetCloseHandle( hReq);
::InternetCloseHandle( hConn);
::InternetCloseHandle( hInet);
return 0;
}
void split_url(char* url,char* host,char* file)
{
int i,sep1=7,sep2=0,urllen=strlen(url);
for(i=sep1;i<strlen(url);i++,sep2++){
if(url[i]=='/') break;
}
strncpy(host,url+sep1,sizeof(char)*sep2);
strncpy(file,url+sep1+sep2,sizeof(char)*(urllen-sep1-sep2));
}
|