gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:54:06 24 4
gpt4 key购买 nike

我通过 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

它与 host:port/url 相关,因为它适用于没有端口的 url。我在使用另一个 Httphelper 类而不是 fluent-builder 时也遇到了同样的错误。防火墙已关闭。

日志:http://pastebin.com/yMMvvdQ3

最佳答案

通过这个 post 发现了它是什么那是 Shoutcast 服务器...

You should be able to connect to 8000 with your web browser and get the DNAS status page. If, on the other hand, you connect to that port with a media player, it'll return the direct MP3 stream. (Unfortunately, in an incredibly boneheaded piece of design, the way SHOUTcast decides which to respond with is by sniffing your User-Agent header for something beginning with Mozilla, so if you're using an alternative browser or blocking your UA you'll not be able to get the status, and if the stream's down you might just get nothing.)

快把我逼疯了..但这很容易解决。我刚刚添加。

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

关于java - 无法使用具有不同服务器端口的 HttpClient 下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3517220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com