2012-03-27 95 views
0

我希望從我的Android應用程序中的HttpGet功能加載從BBC rss飼料的網頁。當我從RSS源鏈接,和我用HttpGet與BBC新聞RSS飼料

HttpGet request = new HttpGet(link); 
ResponseHandler<String> responseHandler = new BasicResponseHandler(); 
try{ 
    String response_str = client.execute(request, responseHandler); 
    textView.setText(response_str); 
    } 

對於來自紐約時報的RSS提要,我可以在自己的網頁中,這意味着該功能對於某些情況下至少工作環境。然而,在英國廣播公司新的情況下,我只得到像

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" 
"http:///www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> 

<html xmlns= "http:///www.w3.org/1999/xhtml" 
xmlns:og="http://opengraphprotocal.org/schema." xml:lang="en-GB"> 

我想知道在那裏我需要處理什麼的任何重定向形勢網頁?否則,如果此代碼適用於某些網頁而不適用於其他網站,則會很奇怪。

感謝您的閱讀。

回答

0

不知道你正在使用的URL,但下面的代碼工作對我來說:

final String feedURLStr = "http://feeds.bbci.co.uk/news/world/rss.xml?edition=uk#"; 
HttpClient client = new DefaultHttpClient(); 
HttpGet method = new HttpGet(feedURLStr); 
ResponseHandler<String> handler = new BasicResponseHandler(); 
final String responseStr = client.execute(method, handler); 
System.out.println(responseStr); 

確認您使用的是有效的供稿網址(部分名單目前可以看到here)。

+0

謝謝,其實我原來的代碼效果很好,我只是忘了向下滾動內容。但是,謝謝你的回覆。 – JLTChiu 2012-04-04 03:43:10