用C#读取wordpress RSS - 内容不同

Gre*_*ire 0 c# wordpress rss

我正在尝试读取由wordpress生成的RSS,并激活全文.在firefox和IE9上,项数据包含以下元素content:encoded:

<content:encoded><![CDATA[bla bla bla]]></content:encoded>            
Run Code Online (Sandbox Code Playgroud)

但是在C#程序中我请求相同的rss url这个节点不存在.我这样做我的C#请求:

   WebClient client = new WebClient();
   client.Encoding = Encoding.UTF8;
   client.Headers.Add("Accept", "application/xml");
   var xml = client.DownloadString(url)
Run Code Online (Sandbox Code Playgroud)

我是否必须在请求中添加标题才能拥有此特定字段?

L.B*_*L.B 5

您不需要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");
}
Run Code Online (Sandbox Code Playgroud)

编辑

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

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();
Run Code Online (Sandbox Code Playgroud)