2010-08-18 55 views
2

我使用Apache的HttpClient通過httpclient-fluent-builder下載http頁面。不能用HttpClient下載不同的服務器端口

這是代碼:

... 
try { 
    response = Http.get("http://fr3.ah.fm:9000/played.html") 
     .use(client)    // use this HttpClient (required) 
     .charset("windows-1252")  // set the encoding... (optional) 
     .asString(); 
} catch (IOException e) { 
    Log.d(TAG, "Error: "+e.toString()); 
    e.printStackTrace(); 
} 
Log.i(TAG, ""+ response); 
... 

問題是,我得到org.apache.http.client.ClientProtocolException

這件事情與主機:端口/ URL,東陽它的URL不工作端口。我還得到了另一個Httphelper類與流利構建器相同的錯誤。防火牆關閉。

的logcat:http://pastebin.com/yMMvvdQ3

+0

如果您在瀏覽器中點擊http://fr3.ah.fm:9000/played.html,它會給你一些有效的東西? – 2010-08-18 22:46:14

+0

是的,我試着從我的常規瀏覽器和模擬器內的Android瀏覽器。 – droidgren 2010-08-18 23:21:40

回答

2

發現了什麼,然後經此post這是SHOUTcast服務器...

你應該能夠與您的網絡連接到8000 瀏覽器並獲取DNAS 狀態頁面。另一方面,如果您使用媒體 連接到該端口,它將返回直接MP3 流。 (不幸的是,在一個令人難以置信的 一件愚蠢的設計, 方式Shoutcast一樣決定要 響應與是通過嗅探你 User-Agent頭的東西 使用Mozilla開始,因此,如果您使用其他瀏覽器是 或 阻止您的UA你不能 獲取狀態,如果流的 下來,你可能只是什麼也得不到。)

開車送我瘋了..但它是一個容易解決。我剛剛添加。

.header("User-Agent", "UserAgent: Mozilla/5.0") 
+0

你不知道你爲我節省了多少努力。謝謝! :) – 2012-07-02 19:57:39

0

嘗試使用HttpHost設置URI和HttpClient.execute使用它()。

我還沒有嘗試過..

相關問題