try
{
CInternetSession httpSession;
CInternetFile* lphtmlFile = (CInternetFile*) httpSession.OpenURL(strUrlPath);// strUrlPath 要下载的网址
if (NULL == lphtmlFile)
{
;
}
CString strAllContent = _T("");
CString strContent = _T("");
while (lphtmlFile->ReadString(strContent))
{
strAllContent += strContent;
}
lphtmlFile->Close();
httpSession.Close();
CFile File;
BOOL bFileRet = File.Open(strUrlFilePath, CFile::modeCreate | CFile::modeWrite); // strUrlFilePath 保存文件的路径
if (FALSE == bFileRet)
{
;
}
File.Write(strAllContent.GetBuffer(0),strAllContent.GetLength()*sizeof(TCHAR));
File.Close();
}
catch (...)
{
//it would throw a exception when the network is disconected.
}