펼쳐두기..
tdafx.h 파일에 #include <afxinet.h> 를 추가
BOOL GetSourceHtml(CString theUrl)
{
// this first block does the actual work
CInternetSession session;
CInternetFile* file = NULL;
try
{
// try to connect to the URL
file = (CInternetFile*) session.OpenURL(theUrl);
}
catch (CInternetException* m_pException)
{
// set file to NULL if there's an error
file = NULL;
m_pException->Delete();
}
// most of the following deals with storing the html to a file
CStdioFile dataStore;
if(file)
{
CString somecode;
BOOL bIsOk = dataStore.Open(_T("C:\\rawHtml.txt"),
CFile::modeCreate
| CFile::modeWrite
| CFile::shareDenyWrite
| CFile::typeText);
if (!bIsOk)
return FALSE;
// continue fetching code until there is no more
while (file->ReadString(somecode) != NULL)
{
somecode += "\r\n";
dataStore.WriteString(somecode);
}
file->Close();
delete file;
}
else
{
dataStore.WriteString(_T("Could not establish a connection with the server..."));
}
return 0;
}


