第一种:可以正常读取UTF8的中文网页:
#import "msxml2.dll"
using namespace MSXML2;
CString fetchUTF8HTMLCode(const char *url)
{
CString respString="";
::CoInitialize(NULL);
try
{
IXMLHTTPRequestPtr xmlrequest;
HRESULT hr=xmlrequest.CreateInstance("Msxml2.XMLHTTP");
if(!SUCCEEDED(hr))
{
AfxMessageBox(_T("无法创建XMLHTTP对象,请检查是否安装了MS XML运行库!"));
}
xmlrequest->open(_bstr_t("GET"),_bstr_t(url),false);
xmlrequest->send();
BSTR bstrbody;
xmlrequest->get_responseText(&bstrbody);
_bstr_t bstrtbody(bstrbody);
respString = LPCTSTR(bstrtbody);
}catch(...){
}
return respString;
}
第二种,可以正常读取GBK的中文网页
#include <afxinet.h> //加入CIneternetSession的引用
CString fetchGBKHTMLCode(const char *url){
CInternetSession mySession(NULL,0);
CHttpFile* myHttpFile=NULL;
CString respString=