开发者

How to check Rss Feed link Is valid or not

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;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜