Click here to Skip to main content
11,796,774 members (67,177 online)
Click here to Skip to main content

HttpWebRequest/Response in a Nutshell - Part 2 - Extending the Web

, 30 Mar 2007 CPOL 28.5K 24
Rate this:
Please Sign up or sign in to vote.
After Part 1 - The basics - We will try to extend our application.


Ok, now that we've created our HttpWebRequest/Response program, we're going to extend that with XML (eXtensible Markup Language).

Why XML?

Because XML is becoming (if it isn't already) the (web)standard for exchanging data. As developers, we'd like to know how it works, isn't it? Smile | :)

Anyhow, this time we're going to create a little RSS reader (command line).

Using the Code

Ok, first, if you don't know about HttpWebRequest/Response yet, visit part 1.
So, we'll start off with some code:

using System;
using System.Collections.Generic;
using System.Net;
using System.Xml;
using System.IO;

namespace RSS_reader
    class MainClass
        public static void Main(string[] args)
            if (args.Length < 1 || args.Length > 1)
		("Usage: {0} RSS-site{1}Example: {0}",
            } else {
                HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(args[0]);
                WebReq.Method = "GET";
                HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
                if (WebResp.StatusCode == HttpStatusCode.OK)
                    Stream Answer = WebResp.GetResponseStream();
                    XmlTextReader response = new XmlTextReader(Answer);
                    while (response.Read())
                        switch (response.NodeType)
                            case XmlNodeType.Element:
                                if (response.Name == "title" ||
                                    response.Name == "description" ||
                                    response.Name == "link" ||
                                    response.Name == "author")
                                    string t = response.Name;
                                    Console.WriteLine(string.Format("{0}: {1}", 
					t, response.Value));
                } else
                    Console.Write(string.Format("Error, wrong statuscode: {0}", 

Ok, I admit, it's VERY basic, but it kind of shows how it's easy to implement XML in your HTTP-oriented program. I'll be extending this article soon though.


  • 31-03-2007 01:00 (local time - Belgium) Started writing document
  • 31-03-2007 01:33 (local time - Belgium) Stopped writing document, this is v0.1


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Belgium Belgium
Started coding at age of 12 (approx.) started out with pascal, went to Delphi, and from Delphi to BC++ (all in one year), did several years with BC++, and later on started to learn some html, php, mysql... Now more into C#, python, php.
Current age: 17

You may also be interested in...

Comments and Discussions

QuestionWhat about posting XML data? Pin
Tom Wright25-Sep-08 9:22
memberTom Wright25-Sep-08 9:22 
GeneralBroken link to Part 1 Pin
Peter Mortensen16-Apr-08 23:12
memberPeter Mortensen16-Apr-08 23:12 
GeneralRe: Broken link to Part 1 Pin
Peter Mortensen16-Apr-08 23:15
memberPeter Mortensen16-Apr-08 23:15 
The correct link appears to be:

Peter Mortensen

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151002.1 | Last Updated 30 Mar 2007
Article Copyright 2007 by CPF_
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid