Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 CoverYourASP --> Get the News --> Part 2

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
55 active users
509 visitors today
1143 pages today
how is this done?
Tools I use

CoverYourASP
Copyright © 1999-2010 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

So now I have a working application to view the results on our web site - but I haven't done any real work. Using MFC's classes even the next part is easy. I'll briefly describe the code as I go but - (here's the copout) - use MSDN to get help on parts you don't understand!

Start by opening an HTTP connection to the news source. CInternetSession is the key to this process - just create one, and call the GetHttpConnection method:

// create an internet session
CInternetSession csiSession;

// parse URL to get server/object/port
CString sGetFromURL ( "http://aspwire.com/getnews.asp?site=secret&lang=1&cnt=10" );

if ( !AfxParseURL ( sGetFromURL, dwServiceType, sServerName, sObject, nPort ) )
   throw;

// open HTTP connection
CHttpConnection* pHTTPServer = NULL;

pHTTPServer = csiSession.GetHttpConnection ( sServerName, nPort );

// get HTTP object
CHttpFile* pFile = NULL;

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];

// transfer the data into our local file
while ( pFile->ReadString ( sRaw, 1023 ) )
   cfRaw.WriteString ( sRaw );

// I've finished with the HTTP objects
// so close them
pFile->Close();
pHTTPServer->Close();

That's the first part done! I now have a file on our local disc that contains the news feed's raw data. It's in the format URL, Date, Type, Title - here's a section of the file I just created:

   http://aspwire.com/redir?2888
   7/28
   article
   Hosting multiple domains on one IP Address
   http://aspwire.com/redir?2865
   7/28
   article
   404 Error Page

Now I have to get the data I need from this file, and format it the way I need.

Part 3: Creating our ASP file...

Featured sponsor
My favorite resources

Tiki Statues - Tiki Masks - Tiki Totems



See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!