使用CInternetSession 获取网页内容。。。解决了ReadString时的乱码

 

CInternetSession session;
CHttpFile *file = NULL; CString
strURL = _T("http://www.baidu.com");
CString strHtml = _T(""); //存放网页数据
try
{ file
=
(CHttpFile*)session.OpenURL(strURL);
} catch(CInternetException
*
m_pException)
{ file = NULL;
m_pException->m_dwError;
m_pException->Delete();
session.Close(); AfxMessageBox(_T("CInternetException"));
} CString strLine; char
sRecived[1024];
if(file != NULL) {
while(file->ReadString((LPTSTR)sRecived,1024)
!=
NULL) {
strHtml += sRecived; } }
else
{
AfxMessageBox(_T("fail")); } session.Close();
file->Close();
delete file; file = NULL;

本文出自 “会飞de树(往github迁移中)” 博客,转载请与作者联系!

你可能感兴趣的:(c,session,internet,休闲,ReadString)