tags:

views:

379

answers:

2

Trying to use RSS.NET. Example on the site is: (C#)

string url = "http://sourceforge.net/export/rss2_sfnews.php?feed";
RssFeed feed = RssFeed.Read(url);
RssChannel channel = (RssChannel)feed.Channels[0];
listBox.DataSource = channel.Items;

However, this fails because I need to access the feed through a proxy. How do I do this?

An overload for RssFeed.Read() takes HttpWebRequest. I think this may be the way of setting this up, but I haven't used this before. Help! :)

+2  A: 
  1. There is an overload of the RssFeed.Read() method that accepts an HttpWebRequest. You can set the proxy on the HttpWebRequest and read it that way. This sets the proxy for the RSS feed in particular. You would need to do this for each feed you read in.
  2. You can set the default proxy using System.Net.WebRequest.DefaultWebProxy, prior to calling RssFeed.Read(String). Do this just once; it will apply to all Rss feeds you read, as well as all other http communicatious going out from your app.
Cheeso
Thanks for the default tip. That is useful to know.
Nick
+4  A: 

You can indeed use the HttpWebRequest overload of the RssFeed.Read() function. The following should work

string url = "http://sourceforge.net/export/rss2_sfnews.php?feed";
string proxyUrl = "http://proxy.example.com:80/";
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
WebProxy proxy = new WebProxy(proxyUrl,true);
webReq.Proxy = proxy;
RssFeed feed = RssFeed.Read(webReq);

If you need a username and password for the proxy there is a more detailed example here.

Bessi
I tried that and I got authentication 401 errors. I fixed that with user and p/w and now I get 500 errors, i.e. internal server error. Is this common? Am I missing something?
Nick