VC++的UNICODE工程和多字节字符集的HTTP请求
来源:互联网 发布:淘宝宝贝发布运费模板 编辑:程序博客网 时间:2024/05/29 07:29
CString CServerSession::httpGetRequest(CString url){CInternetSession m_InetSession;CString strHtml;try{CHttpFile* pFile =(CHttpFile*)m_InetSession.OpenURL(url);if (pFile!=NULL){DWORD statusCode; pFile->QueryInfoStatusCode(statusCode); if (statusCode==HTTP_STATUS_OK) { CString strLine;while (pFile->ReadString(strLine)>0)strHtml += strLine;}}m_InetSession.Close();pFile->Close();delete pFile;}catch (CInternetException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);AfxMessageBox(info);}catch (CMemoryException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);AfxMessageBox(info);}catch (CFileException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);AfxMessageBox(info);}catch (CException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);AfxMessageBox(info);}return strHtml;}CString CServerSession::httpPostRequest(CString requestData,CString pageUrl){CInternetSession m_InetSession; //设置不缓冲CHttpConnection* pServer = NULL;CHttpFile* pFile = NULL;CString strHtml;//POST过去的数据requestDatatry{INTERNET_PORT nPort; //端口nPort=80;pServer = m_InetSession.GetHttpConnection("127.0.0.1", nPort);pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,pageUrl);pFile->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");pFile->AddRequestHeaders("Accept: */*");pFile->SendRequestEx(requestData.GetLength());pFile->WriteString(requestData);pFile->EndRequest();DWORD dwRet;pFile->QueryInfoStatusCode(dwRet);if (dwRet == HTTP_STATUS_OK){CString strLine;while (pFile->ReadString(strLine)>0)strHtml += strLine;}m_InetSession.Close();pFile->Close();pServer->Close();delete pFile;delete pServer;}catch (CInternetException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);AfxMessageBox(info);}catch (CMemoryException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);AfxMessageBox(info);}catch (CFileException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);AfxMessageBox(info);}catch (CException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);AfxMessageBox(info);}return strHtml;}
以上是字节字符集的
下面是UNICODE工程的
CString CServerSession::httpGetRequest(CString url){CInternetSession m_InetSession;CString strHtml;try{CHttpFile* pFile =(CHttpFile*)m_InetSession.OpenURL(url);if (pFile!=NULL){DWORD statusCode; pFile->QueryInfoStatusCode(statusCode); if (statusCode==HTTP_STATUS_OK) { TCHAR buf[1024]= {0};char tmp[2048] = {0};while(pFile->ReadString(buf, 1024)) {for(int i=0, j=0; i<lstrlen(buf); i++, j+=2){tmp[j] = LOBYTE(buf[i]);//取字的低字节tmp[j+1] = HIBYTE(buf[i]);//取字的高字节}CString ss(tmp);strHtml+=ss;}}}m_InetSession.Close();pFile->Close();delete pFile;}catch (CInternetException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);}catch (CMemoryException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);}catch (CFileException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);}catch (CException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);}return strHtml;}CString CServerSession::httpPostRequest(char* requestData,CString pageUrl){CInternetSession m_InetSession; //设置不缓冲CHttpConnection* pServer = NULL;CHttpFile* pFile = NULL;CString strHtml;//POST过去的数据requestDatatry{INTERNET_PORT nPort; //端口nPort=80;pServer = m_InetSession.GetHttpConnection(SERVER_URL, nPort);pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,pageUrl);pFile -> AddRequestHeaders(_T("Content-Type: application/x-www-form-urlencoded")); pFile -> AddRequestHeaders(_T("Accept: */*"));pFile->SendRequest(NULL,NULL,requestData,(DWORD)strlen(requestData));DWORD dwRet;pFile->QueryInfoStatusCode(dwRet);if (dwRet == HTTP_STATUS_OK){TCHAR buf[1024]= {0};char tmp[2048] = {0};while(pFile->ReadString(buf, 1024)) {for(int i=0, j=0; i<lstrlen(buf); i++, j+=2){tmp[j] = LOBYTE(buf[i]);//取字的低字节tmp[j+1] = HIBYTE(buf[i]);//取字的高字节}strHtml+=UTF8ToUnicode(tmp);}}m_InetSession.Close();pFile->Close();pServer->Close();delete pFile;delete pServer;}catch (CInternetException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);}catch (CMemoryException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);}catch (CFileException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);}catch (CException* e){TCHAR info[1024] = {0};e->GetErrorMessage(info,1024);}return strHtml;}
- VC++的UNICODE工程和多字节字符集的HTTP请求
- VC++的UNICODE工程和多字节字符集的HTTP请求
- unicode和多字节字符集的区别
- 关于VC多字节字符集和unicode宽字符集的使用和问题(转)
- VC/多字节字符集和unicode宽字符集
- unicode和MBCS(多字节字符集)的关系
- unicode和MBCS(多字节字符集)的关系
- unicode和MBCS(多字节字符集)的关系
- unicode和MBCS(多字节字符集)的关系
- VC++的多字符集和unicode字符集转换大全(CString转char*等)
- Unicode字符集 和 多字节字符集 关系
- Unicode字符集和多字节字符集关系
- Unicode字符集和多字节字符集关系
- Unicode字符集和多字节字符集关系
- Unicode字符集和多字节字符集关系
- Unicode字符集和多字节字符集关系
- Unicode字符集和多字节字符集关系
- Unicode字符集和多字节字符集关系
- 了解JavaScript中的内置对象
- HDU 1009 FatMouse' Trade
- sgu275 To xor or not to xor ----高斯消元复习
- HDU 1012 u Calculate e
- HNOI2002 营业额统计(splay tree)
- VC++的UNICODE工程和多字节字符集的HTTP请求
- 在开发板上挂载NFS
- HDU 1013 Digital Roots
- nutch的conf中的配置文件分类和使用
- TRIE树 --- 字典树
- ASM 常用概念解释
- IOS5基础之十一-----定制表视图单元
- Oracle查询所有序列
- js内存泄露