CInternetSession session;
CInternetFile *pFile = NULL;
try{
pFile = (CInternetFile*)session.OpenURL("
http://www.baidu.com"); //打开链接
}catch(CInternetException *pEx){
pEx->ReportError();
pFile = NULL;
pEx->Delete();
}
if(pFile)
{
char *buf = new char[9999];
UINT nCount = pFile->Read(buf,9999); //把网页数据读入缓冲
HANDLE hFile = CreateFile("baidu.html",GENERIC_WRITE,0,NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,0); //创建文件
if(INVALID_HANDLE_VALUE == hFile)
{
MessageBox("创建文件失败!");
}
else
{
CFile file((int)hFile);
file.Write(buf,nCount); //把缓冲中的数据写入文件
}
delete buf;
}
session.Close();