Reading wordpress RSS with C# – Content different

I’m trying to read a RSS generated by wordpress with full text activated. On firefox and IE9 an item data contains the element content:encoded:

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

but when in a C# program I request the same rss url this node is not present. I do my C# request like this:

Read More
   WebClient client = new WebClient();
   client.Encoding = Encoding.UTF8;
   client.Headers.Add("Accept", "application/xml");
   var xml = client.DownloadString(url)

Does I have to add an header to the request to have this specific field?

Related posts

Leave a Reply

2 comments

  1. You don’t need WebClient to download 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)+"nn");
    }
    

    EDIT

    The problem is related with compression. If the client doesn’t support compression, then server doesn’t send contents.

    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();
    
  2. I’m guessing WordPress is choosing the “wrong” output format based on your Accept header. Which feed is used is decided in /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'
    );
    

    so instead of text/xml, try accepting application/rss+xml.