获取网页的源文件出现乱码!
我用 如下方法获取某网页的源文件,并保存到本地。我发现获取到的源文件中会出现一些乱码
如 "瓠?瓠?瓠韩“ 之类。这是什么原因造成的,怎么解决阿?
代码如下;
const UINT MAXBUF=1024*200;
CInternetSession session;
CHttpConnection* pConnection=NULL;
CHttpFile* pFile=NULL;
CHAR* buffer=new TCHAR[MAXBUF];
CHAR* tempbuffer=new TCHAR[1024];
strcpy(buffer,"\0");
strcpy(tempbuffer,"\0");
UINT nBytesRead=0;
UINT nByte=0;
try{
pConnection=session.GetHttpConnection(strServer,1,80,NULL,NULL);
pFile=pConnection->OpenRequest(1,strFile);
pFile->SendRequest();
}
catch(CInternetException* e)
{
e->Delete();
}
while((nByte=pFile->Read(tempbuffer,1024))!=0) //读文件到缓冲区
{
strcat(buffer,tempbuffer);
strcpy(tempbuffer,"\0");
nBytesRead+=nByte;
}
buffer[nBytesRead]='\0';
FILE* fp=fopen("C:\\source.txt","wb");//保存到本地
fwrite(buffer,nBytesRead,1,fp);
fclose(fp);