1

为什么 MS Syndication 类不接受有效的 RSS 提要?

public static Stream GetResponseStream(string url)
{
    var uri = new Uri(url, true);
    WebRequest request = WebRequest.Create(uri);
    request.Method = WebRequestMethods.Http.Get;
    WebResponse response = request.GetResponse();
    return response.GetResponseStream();
}

public static void GetRSS()
{
    using (Stream stream1 = GetResponseStream("http://www.lostfilm.tv/rssdd.xml"))
    {
        try
        {
            XmlReader xmlReader = XmlReader.Create(stream1);
            var feeds = SyndicationFeed.Load(xmlReader);
        }
        catch (Exception ex)
        {
            // Error :( 
        }
    }
}

RSS 本身是有效的:

http://validator.w3.org/appc/check.cgi?url=http%3A%2F%2Fwww.lostfilm.tv%2Frssdd.xml

4

1 回答 1

1

SyndicationFeed仅支持 RSS 2.0 和 Atom 1.0(您的 RSS 版本为 0.91)。

您可以使用外部库,例如Argotic Syndication Framework

使用NuGet安装包:

Install-Package Argotic.Core

然后尝试:

var feed = RssFeed.Create(new Uri("http://www.lostfilm.tv/rssdd.xml", true));
foreach (var post in feed.Channel.Items)
{
    Console.WriteLine(post.Title);
}
于 2013-01-18T14:19:37.103 回答