12

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)

Szymon
  • 42,577
  • 16
  • 96
  • 114
Jona
  • 13,325
  • 15
  • 86
  • 129
  • Notice the `okhttp` there. AFAIK HttpURLConnection implementation has been replaced by Square's OkHTTP in Kitkat. – laalto Nov 02 '13 at 08:04
  • Yes, I thought something changed under the hood. This stinks. I really need to figure out a way around it. Any recommendations? – Jona Nov 02 '13 at 18:36

3 Answers3

6

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?

Community
  • 1
  • 1
Jona
  • 13,325
  • 15
  • 86
  • 129
0

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"

jonathanrz
  • 4,206
  • 6
  • 35
  • 58
  • 1
    Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Feb 03 '14 at 13:59
0

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();
Tom Susel
  • 3,397
  • 1
  • 24
  • 25