无法使用具有不同服务器端口的HttpClient下载

时间:2010-08-18 22:23:07

标签: java android httpclient

我通过httpclient-fluent-builder使用Apache的HttpClient来下载http页面。

这是代码:

...
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

这与主机:port / url有关,因为它适用于没有端口的网址。我也得到了另一个Httphelper类与fluent-builder相同的错误。防火墙已关闭。

Logcat:http://pastebin.com/yMMvvdQ3

2 个答案:

答案 0 :(得分:2)

通过这个post发现它是Shoutcast服务器......

  

您应该可以连接到8000   使用您的网络浏览器并获取DNAS   状态页面。另一方面,如果   您使用媒体连接到该端口   播放器,它将返回直接MP3   流。 (不幸的是,在   令人难以置信的骷髅头设计,   SHOUTcast决定哪个方式   回应是通过嗅探你的   用户代理标题   从Mozilla开始,所以如果你是   使用替代浏览器或   阻止你的UA,你将无法做到   获取状态,如果是流   你可能什么也没得到。)

让我疯狂..但这很容易解决。我刚补充说。

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

答案 1 :(得分:0)

尝试使用HttpHost设置uri并在HttpClient.execute()中使用它。

我还没试过..

相关问题