void CHTTPgetView::OnInitialUpdate() { CHtmlView::OnInitialUpdate(); // the URL we'll display at the end CString sURL ( "http://CoverYourASP.com/default.asp#news" ); // create an internet session CInternetSession csiSession; CHttpConnection* pHTTPServer = NULL; CFtpConnection* pFTPServer = NULL; CHttpFile* pFile = NULL; CString sGetFromURL ( "http://aspwire.com/getnews.asp?site=secret&lang=1&cnt=10" ); CString sSendToURL ( "ftp://CoverYourASP.com/" ); try { // parse URL to get server/object/port CString sServerName; CString sObject; INTERNET_PORT nPort; DWORD dwServiceType; if ( !AfxParseURL ( sGetFromURL, dwServiceType, sServerName, sObject, nPort ) ) throw; // open HTTP connection pHTTPServer = csiSession.GetHttpConnection ( sServerName, nPort ); // get HTTP object pFile = pHTTPServer->OpenRequest ( CHttpConnection::HTTP_VERB_GET, sObject, NULL, 1, NULL, NULL, INTERNET_FLAG_RELOAD ); pFile->SendRequest(); // open file to store raw data into CStdioFile cfRaw ( "News.txt", CFile::modeCreate | CFile::modeReadWrite ); TCHAR sRaw [1024]; while ( pFile->ReadString ( sRaw, 1023 ) ) cfRaw.WriteString ( sRaw ); pFile->Close(); pHTTPServer->Close(); // open file to store formatted data into TCHAR* sNewsFile = _T( "News.asp" ); CStdioFile cfASP ( sNewsFile, CFile::modeCreate | CFile::modeWrite ); cfASP.WriteString ( _T("<%\nfunction ShowNews ( )\n{\n") ); cfASP.WriteString ( _T("\tOut('\"News');\n") ); cfASP.WriteString ( _T("\tOut('   (Read how this is done)

');\n") ); cfASP.WriteString ( _T("\tOut('');\n") ); cfRaw.SeekToBegin (); CString sLine; bool bNewRow = true; for (int i=0; ; i++) { if ( FALSE == cfRaw.ReadString ( sLine ) ) break; switch ( i % 4 ) { case 0: // URL cfASP.WriteString ( _T("\tOut('") ); if ( bNewRow ) cfASP.WriteString ( _T ( "" ) ); bNewRow = !bNewRow; cfASP.WriteString ( _T("") ); if ( bNewRow ) cfASP.WriteString ( _T ( "" ) ); cfASP.WriteString ( _T("');\n") ); break; } } cfASP.WriteString ( _T("\tOut('
• ") ); break; case 3: // title sLine.Replace ( "'", "\\'" ); cfASP.WriteString ( sLine ); cfASP.WriteString ( _T("
');\n") ); cfASP.WriteString ( _T("}\n%>") ); // close files cfRaw.Close (); cfASP.Close (); // now upload file to my website if ( !AfxParseURL ( sSendToURL, dwServiceType, sServerName, sObject, nPort ) ) throw; // open FTP connection pFTPServer = csiSession.GetFtpConnection ( sServerName, _T( "username" ), _T( "password" ), nPort ); // change to utils folder pFTPServer->SetCurrentDirectory ( _T( "utils" ) ); // put the new file in the folder pFTPServer->PutFile ( sNewsFile, sNewsFile ); } // handle any exceptions that occured - since this is run // offline (not on server) we'll just use MessageBox catch (CException* e) { TCHAR szErr[1024]; e->GetErrorMessage(szErr, 1024); AfxMessageBox ( szErr, MB_OK, 0 ); e->Delete(); } // tidy up if (pFile != NULL) delete pFile; if (pHTTPServer != NULL) delete pHTTPServer; if (pFTPServer != NULL) delete pFTPServer; csiSession.Close(); // now view the results on our web page! Navigate2 (sURL, NULL, NULL); }