使用C#阅读wordpress RSS-内容不同

使用C#阅读wordpress RSS-内容不同,c#,wordpress,rss,C#,Wordpress,Rss,我试图阅读wordpress生成的RSS,并激活全文。在firefox和IE9上,项目数据包含元素content:encoded: <content:encoded><![CDATA[bla bla bla]]></content:encoded> 我是否必须在请求中添加一个标题才能包含此特定字段?我猜Wordpress根据您的接受标题选择了“错误”的输出格式。使用哪种提要由/wp content/feed.php决定: $types

我试图阅读wordpress生成的RSS,并激活全文。在firefox和IE9上,项目数据包含元素
content:encoded

<content:encoded><![CDATA[bla bla bla]]></content:encoded>            

我是否必须在请求中添加一个标题才能包含此特定字段?

我猜Wordpress根据您的
接受
标题选择了“错误”的输出格式。使用哪种提要由
/wp content/feed.php
决定:

$types = array(
    'rss'  => 'application/rss+xml',
    'rss2' => 'application/rss+xml',
    'rss-http'  => 'text/xml',
    'atom' => 'application/atom+xml',
    'rdf'  => 'application/rdf+xml'
);

因此,不要使用
text/xml
,而是尝试接受
application/rss+xml

我猜Wordpress根据您的
Accept
标题选择了“错误”的输出格式。使用哪种提要由
/wp content/feed.php
决定:

$types = array(
    'rss'  => 'application/rss+xml',
    'rss2' => 'application/rss+xml',
    'rss-http'  => 'text/xml',
    'atom' => 'application/atom+xml',
    'rdf'  => 'application/rdf+xml'
);

因此,不要使用
text/xml
,而是尝试接受
application/rss+xml

您不需要WebClient来下载rss

XDocument wp = XDocument.Load("http://wordpress.org/news/feed/");
XNamespace ns = XNamespace.Get("http://purl.org/rss/1.0/modules/content/");

foreach (var content in wp.Descendants(ns + "encoded"))
{
    Console.WriteLine(System.Net.WebUtility.HtmlDecode(content.Value)+"\n\n");
}
编辑

这个问题与压缩有关。如果客户端不支持压缩,则服务器不发送内容

WebClient web = new WebClient();
web.Headers["Accept-Encoding"] = "gzip,deflate,sdch";

var zip = new System.IO.Compression.GZipStream(
    web.OpenRead("http://www.whiskymag.fr/feed/?post_type=sortir"), 
    System.IO.Compression.CompressionMode.Decompress);

string rss = new StreamReader(zip, Encoding.UTF8).ReadToEnd();

下载rss不需要WebClient

XDocument wp = XDocument.Load("http://wordpress.org/news/feed/");
XNamespace ns = XNamespace.Get("http://purl.org/rss/1.0/modules/content/");

foreach (var content in wp.Descendants(ns + "encoded"))
{
    Console.WriteLine(System.Net.WebUtility.HtmlDecode(content.Value)+"\n\n");
}
编辑

这个问题与压缩有关。如果客户端不支持压缩,则服务器不发送内容

WebClient web = new WebClient();
web.Headers["Accept-Encoding"] = "gzip,deflate,sdch";

var zip = new System.IO.Compression.GZipStream(
    web.OpenRead("http://www.whiskymag.fr/feed/?post_type=sortir"), 
    System.IO.Compression.CompressionMode.Decompress);

string rss = new StreamReader(zip, Encoding.UTF8).ReadToEnd();

我尝试了application/rss+xml(还有application/rdf+xml),但内容节点仍然不在这里!是否考虑了另一个标题?我尝试了application/rss+xml(以及application/rdf+xml),但内容节点仍然不在这里!是否考虑了另一个标题?@Gregoire,上面的例子很有效。我在发帖前试过了。你使用不同的url吗?我个人不使用XDocument.Load从客户端加载,因为它是单线程的,如果目标站点运行缓慢,我可能会看到我的UI被锁定。如果您要使用这个,我建议不要在UI线程中使用它。@Gregoire,上面的例子很有效。我在发帖前试过了。你使用不同的url吗?我个人不使用XDocument.Load从客户端加载,因为它是单线程的,如果目标站点运行缓慢,我可能会看到我的UI被锁定。如果您要使用这个,我建议不要在UI线程中使用它。