Results 1 to 5 of 5

Thread: [VS 2005] RSS 404 error problems

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    271

    [VS 2005] RSS 404 error problems

    Hi,

    I'm trying to learn how to deal with RSS feeds, I'm just querying the BBC's weatherfeed at the momement.

    I am trying to detect if the feed is there or not, if not I just want it to write to the console "feed NOT available"

    I've added some code to check for the Error 404, but it doesnt work, I still end up getting an error.

    And ideas?

    Cheers,

    My CODE:
    Code:
           public class WeatherChecker
        {
            
            public void getCountries()
            {
                string server = "http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/";
                int i = 0;
    
                bool XMLReturned = true;
                DataSet ds_XML = new DataSet();
    
                do
                {
                    i++;
                    string citycode = i.ToString("0000");
    
                    try
                    {
                        ds_XML.ReadXml(server + citycode + ".xml");
    
                        //Send Response
                        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(server + citycode + ".xml");
    
                        webRequest.AllowAutoRedirect = false; // In case the server is configured to redirect on 404
    
    
                        //Get Result
                        HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
    
                        if (webResponse.StatusCode != HttpStatusCode.OK)
                        {
                            Console.Out.WriteLine("feed NOT available");
    
                         }
                         else
                         {
                             Console.Out.WriteLine(" ");
                             Console.Out.WriteLine("feed IS available");
    
                             StreamReader WeatherStream = new StreamReader(webResponse.GetResponseStream());
    
                             ds_XML.ReadXml(WeatherStream);
    
                             string strTitle = ds_XML.Tables["channel"].Rows[0]["title"].ToString();
    
                             if (ds_XML.Tables.Count > 0)
                             {
                                 string TitleParts = strTitle.Replace("BBC - Weather Centre - Forecast for","");
                                 string[] City = TitleParts.Split(',');
                                
                                 XMLReturned = true;
    
                                 Console.Out.WriteLine(citycode + " - " + City[0]);
                                 ds_XML.Clear();
                             }
                             else
                             {
                                 XMLReturned = false;
                             }
                            
                         }
    
    
      
    
                }
                    catch (Exception er)
                    {
                        Console.Out.WriteLine(er);
                    }
                }
                while (XMLReturned == true);
    
            }
    
        }
    Last edited by §tudz; Mar 26th, 2007 at 05:23 AM. Reason: change to string editing - on code
    §tudz

    Studzworld.com - Portfolio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width