2016년 12월 22일 목요일

MFC, HTTPRest

중국 애들이 잘해 ^^


   CString StrServer = NULL;
   CString strHtml = NULL;
   StrServer ="여기에 주소적고";
   CInternetSession *pSession = new CInternetSession;
   pSession->SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT,5000);
   //设置接收信息超时时间
   pSession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5000);
   //设置连接超时信息
   CHttpFile* pFile =(CHttpFile*)pSession->OpenURL((LPCTSTR)StrServer, 1,INTERNET_FLAG_RELOAD |INTERNET_FLAG_TRANSFER_BINARY); 
   //建立HTTP连接
   DWORD dwStatusCode;    
   pFile->QueryInfoStatusCode(dwStatusCode); 
   if(dwStatusCode == HTTP_STATUS_OK)   
   {   
       CString strLength = NULL; 
       CString strHeaders = NULL; 
       pFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH,strLength); 
       pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF,strHeaders); 
       //读取HTTP长度及包头
       //AfxMessageBox(ConvertUTF8toGB2312(strLength,strlen(strLength)));
       //AfxMessageBox(ConvertUTF8toGB2312(strHeaders,strlen(strHeaders)));
       long lLength = 4096 * 100; 
       byte* pbHtml = new byte[lLength]; 
       memset(pbHtml, 0, lLength); 
       byte sRecived[512]; 
       int iIndex = 0; 
       int num = 0; 
       while((num = pFile->Read(sRecived,512))> 0 ) 
       { 
           memcpy(pbHtml+iIndex, sRecived, num); 
           iIndex+=num; 
       } 
       pbHtml[iIndex] = NULL; 
       //读取HTTP内容
       strHtml = (CHAR *)pbHtml; 
       strHtml = ConvertUTF8toGB2312((CHAR *)pbHtml,strlen((CHAR*)pbHtml));
       //UTF8转换成GB2312
       AfxMessageBox(strHtml);
   }

댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...