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);
   }

댓글 없음:

댓글 쓰기

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

대학원생의 투고 지도 ④ (완결) — 논문의 수준이란 무엇인가: 사다리와 사분위, 첫 논문 전략

완결편이다. "논문 수준"이라는 말을 해부하고, 에듀테크 석사생의 첫 논문 전략으로 마친다. 학위논문과 학술지 논문은 다른 장르다 먼저 가장 흔한 혼동부터. 학위논문(thesis)은 "내가 연구를 수행할 줄 안다...