#include <afxinet.h>
#include <iostream>
using namespace std;
bool readHtml(string url, string& s)
{
CInternetSession session("unknown");
CHttpFile* pFile = (CHttpFile*)session.OpenURL(url.c_str());
if (pFile)
{
char buf[8192];// = {0};
int count;
for (;;)
{
count = pFile->Read(buf, sizeof(buf) - 1);
if (count <= 0) break;
buf[count] = 0;
s.append(buf);
}
pFile->Close();
delete pFile;
return true;
}
return false;
}
bool saveFile(string file, string& s)
{
CFile cf(file.c_str(), CFile::modeCreate | CFile::modeWrite);
cf.WriteHuge(s.c_str(), s.size());
//cf.Flush();
cf.Close();
return true;
}
main()
{
string s;
if (readHtml("http://www.google.com", s))
saveFile("c://google.html", s);
}