I want check that that provided Rss开发者_JAVA百科 feed Link Is valid or not and is it working right now?
Just load the URL and check that it is actually an RSS feed.
try {
var feedDoc = XDocument.Load(url);
return ValidateRss(feedDoc); // implementation left as an exercise for the reader.
}
catch(HttpException) { // perhaps others
return false;
}
Use below code to check RSS URL:
using System.ServiceModel.Syndication;
public static bool IsValidFeedUrl(string url)
{
bool isValid = true;
try
{
XmlReader reader = XmlReader.Create(url);
Rss20FeedFormatter formatter = new Rss20FeedFormatter();
formatter.ReadFrom(reader);
reader.Close();
}
catch
{
isValid = false;
}
return isValid;
}
精彩评论