下载网页

 

BOOL Download( CString szURL, CString szDstFile )
{
	BOOL res = false;
	CInternetSession Session;
	CHttpFile *pHttpFile = NULL;

	try{
		pHttpFile = (CHttpFile*)Session.OpenURL(szURL);
	}catch(CInternetException * m_pException){
		pHttpFile = NULL;
		m_pException->m_dwError;
		m_pException->Delete();
		Session.Close();
		res = false;
	}

	CString strLine;
	CFile xmlFile;
	BOOL bResult = xmlFile.Open(szDstFile, CFile::modeCreate | CFile::modeWrite);
	if(pHttpFile != NULL && bResult)
	{
		while(pHttpFile->ReadString(strLine) != NULL)
		{
			xmlFile.Write(strLine, strLine.GetLength());
		}
		xmlFile.Close();
		res = true;
	}
	else
	{
		res = false;
	}

	Session.Close();
	pHttpFile->Close();
	delete pHttpFile;
	pHttpFile = NULL;
	
	return res;
}
 

 

 

 

你可能感兴趣的:(下载)