如何检查Rss Feed链接是否有效

时间:2011-04-04 10:46:43

标签: asp.net rss

我想检查提供的Rss Feed链接是否有效,是否正常工作?

2 个答案:

答案 0 :(得分:0)

只需加载网址并检查它实际上是否是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;
}

答案 1 :(得分:0)

使用以下代码检查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;
    }