首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

c++中保存网页出现乱码,该怎么处理

2012-05-14 
c++中保存网页出现乱码我使用CHttp 和 CInternetSession 读取指定网址的网页保存后出现乱码。我读取的是万

c++中保存网页出现乱码
我使用CHttp 和 CInternetSession 读取指定网址的网页 保存后出现乱码。我读取的是万方数据库的网页
例如网址是: http://s.wanfangdata.com.cn/paper.aspx?f=SimpleSearch&q=%E5%A5%A5%E6%96%AF%E5%8D%A1%00
我该怎么办?
估计是编码的问题,但我不知道如何解决。
谢谢兄弟姐妹的帮吗?

string webname=reswebfile_path;
webname.append(wanfangname);
webname.append(".html");
cout<<webname<<endl;
ofstream* outfile=new ofstream(webname.c_str(),ios::out);
CInternetSession session("HttpClient");
CHttpFile* pfile = (CHttpFile *)session.OpenURL(wanfangurl.c_str());

DWORD dwStatusCode;
pfile->QueryInfoStatusCode(dwStatusCode);
if(dwStatusCode==HTTP_STATUS_OK)
{
CString data;
while (pfile -> ReadString(data))
{
outfile->write(data,strlen(data));
*outfile<<endl;
}

}
pfile->Close();
delete pfile;
pfile=NULL;
session.Close();
outfile->close();
delete outfile;
outfile=NULL;

[解决办法]
应该是字符编码的问题,

热点排行
Bad Request.