Android 4.4 http api bugs?

时光毁灭记忆、已成空白 提交于 2019-12-04 00:26:46

问题


I decided to start testing my app with Android 4.4 and noticed that the Android HTTP connection APIs are much stricter than before? I have never had this issue and I assume it is some type of bug.

I'm connecting to SHOUTcast broadcasts that contain the particular icy header response.

Has anyone seen this issue? How can I get around it?

URL used for this test:

http://50.117.121.162:80

Logcat of exception:

11-01 23:47:57.299: E/ConnectHelper(3081): java.net.ProtocolException: Unexpected status line: ICY 200 OK 11-01 23:47:57.299: E/ConnectHelper(3081): at com.android.okhttp.internal.http.RawHeaders.setStatusLine(RawHeaders.java:108) 11-01 23:47:57.299: E/ConnectHelper(3081): at com.android.okhttp.internal.http.RawHeaders.fromBytes(RawHeaders.java:308) 11-01 23:47:57.299: E/ConnectHelper(3081): at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:135) 11-01 23:47:57.299: E/ConnectHelper(3081): at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:644) 11-01 23:47:57.299: E/ConnectHelper(3081): at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347) 11-01 23:47:57.299: E/ConnectHelper(3081): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296) 11-01 23:47:57.299: E/ConnectHelper(3081): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503) 11-01 23:47:57.299: E/ConnectHelper(3081): at com.vblast.xiialive.media.streamers.ConnectHelper.connectWorker(ConnectHelper.java:176) 11-01 23:47:57.299: E/ConnectHelper(3081): at com.vblast.xiialive.media.streamers.ConnectHelper.run(ConnectHelper.java:143) 11-01 23:47:57.299: E/ConnectHelper(3081): at java.lang.Thread.run(Thread.java:841)


回答1:


On Android 4.4 things did change under the hood and the none standard SHOUTcast ICY header response is no longer supported. Just like the Apache HTTPClient library.

What I had to do can be found on this post:
How to parse a none standard HTTP response?




回答2:


Jona answer is right, but if you are using AACPlayer(https://code.google.com/p/aacplayer-android/) to play your SHOUTcast, here is a simpler solution: https://code.google.com/p/aacdecoder-android/wiki/HandlingShoutcastStreams

Also, I needed to change my url from "http://example.org" to "icy://example.org"




回答3:


I've implemented a solution based on the Apache HttpClient, you can find it as a gist here.

Here is how to use it:

IcyGetRequest request = new IcyGetRequest(urlStr);
HttpResponse response = request.get();
int responseCode = response.getStatusLine().getStatusCode();


来源:https://stackoverflow.com/questions/19738798/android-4-4-http-api-bugs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!