Chris L Chris L - 5 months ago 47
C# Question

XmlReader Error in reading RSS Feed

I am trying to read an RSS feed from with the following code:

//Different RSS Links
string deviant_rsslink = @"";
string blogspot_rsslink = @"";

//Reading the links
XmlReader reader = XmlReader.Create(deviant_rsslink); //LINE WHERE ERROR OCCURS
SyndicationFeed feed = SyndicationFeed.Load(reader);
foreach (SyndicationItem item in feed.Items)
String subject = item.Title.Text;
Console.WriteLine("Subjext is: " + subject + "\n");

...and I get the error:

"The underlying connection was closed: The connection was closed unexpectedly."

At first I thought deviantart might be blocking my IP so I tried this from different computers with differing IPs however the error persists, so it seems that is not the issue. To make things more difficult to track, the code works with no error at

What should I try to fix this?


You site requires User-Agent header be set

Below code should work..

string rss = null;
using (var wc = new Webclient())
    wc.Headers["User-Agent"] = "SO/1.0";
    rss = wc.DownloadString(deviant_rsslink);
XmlReader reader = XmlReader.Create(new StringReader(rss));