MFC怎样发送http请求并接受返回的结果?

来源:互联网 发布:淘宝返利网是怎么回事 编辑:程序博客网 时间:2024/04/30 08:45
#include <afxinet.h>
CString   httpsource="";   CInternetSession   session1(NULL,0);   //CInternetSession session1(NULL,0,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,INTERNET_FLAG_DONT_CACHE);CHttpFile*   pHTTPFile=NULL;   try{   pHTTPFile=(CHttpFile*)session1.OpenURL(href);   //session1.   }catch(CInternetException){   pHTTPFile=NULL;   }   if(pHTTPFile)   {   CString   text;   for(int   i=0;pHTTPFile->ReadString(text);i++)   {   //在这里把UTF8转换成宽字符
char *pStr = text.GetBuffer(text.GetLength()); //取得str对象的原始字符串int nBufferSize = MultiByteToWideChar(CP_UTF8, 0, pStr, -1, NULL, 0); //取得所需缓存的多少wchar_t *pBuffer = (wchar_t*)malloc(nBufferSize * sizeof(wchar_t));//申请缓存空间MultiByteToWideChar(CP_UTF8, 0, pStr, -1 , pBuffer, nBufferSize*sizeof(wchar_t));//转码//MessageBoxW(NULL, pBuffer, L"Text", MB_OK); //显示httpsource=httpsource+pBuffer+"\r\n";free(pBuffer); //释放缓存//MessageBox(text);   }   pHTTPFile->Close();   delete   pHTTPFile;   }

0 0