Winnet

#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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值