2012-02-17 2 views
0

나는 풀 텍스트 활성화와 함께 wordpress에 의해 생성 된 RSS를 읽으려고합니다.C#으로 wordpress RSS를 읽으십시오 - 내용이 다릅니다

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

하지만 C# 프로그램에서 I는 동일한 RSS URL을 요청하면,이 노드는 존재하지 않는다 : 파이어 폭스 IE9의 항목 데이터가 content:encoded 요소를 포함한다. 다음과 같이 C# 요청을합니다.

요청에이 특정 필드를 추가해야합니까?

답변

5

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"); 
} 

EDIT

문제는 압축과 관련된다. 클라이언트가 압축을 지원하지 않으면 서버는 내용을 보내지 않습니다.

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(); 
+0

내용 : 인코딩 된 상태가 여전히 여기에 없습니다. – Gregoire

+0

@Gregoire, 위의 예제가 작동합니다. 게시하기 전에 시도했습니다. 다른 URL을 사용합니까? –

+0

URL을 내가 시도 : http://www.whiskymag.fr/feed/?post_type=sortir – Gregoire

0

저는 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을 받아보십시오.

+0

나는 응용 프로그램/rss + xml (및 응용 프로그램/rdf + xml)을 시도했지만 콘텐츠 노드는 아직 여기에 없습니다! 계정에 사용 된 다른 헤더가 있습니까? – Gregoire

관련 문제