Reputation: 103
I am trying to read an RSS feed from http://backend.deviantart.com/rss.xml?q=gallery:duster132/23316533&type=deviation with the following code:
//Different RSS Links
string deviant_rsslink = @"http://backend.deviantart.com/rss.xml?q=gallery:duster132/23316533&type=deviation";
string blogspot_rsslink = @"http://fightpunch.blogspot.com/feeds/posts/default";
//Reading the links
XmlReader reader = XmlReader.Create(deviant_rsslink); //LINE WHERE ERROR OCCURS
SyndicationFeed feed = SyndicationFeed.Load(reader);
reader.Close();
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 http://fightpunch.blogspot.com/feeds/posts/default.
What should I try to fix this?
Upvotes: 1
Views: 1317
Reputation: 1013
In my case SSL was disabled and TLS was only allowed. I changed to using a HTTPWebRequest instead. Please note that I am using .NET 4.0 and do not have TLS1.2 as option so I hardcoded the value (3072) for that:
Dim doc As New XmlDocument()
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(FeedAddress), HttpWebRequest)
ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)
req.Method = "GET"
Dim myHttpWebResponse As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
Dim response As WebResponse = req.GetResponse
Dim streamResponse As Stream = response.GetResponseStream
doc.Load(streamResponse)
Upvotes: 1
Reputation: 116098
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));
Upvotes: 2