0

I have developed an Android app which sends/gets some data to/from server. The app works fine, however, on Android KitKat 4.4.2 the app throws an exception:

"java.net.ProtocolException: Unexpected status line: ��".

Please tell me how to get rid of it and why this is happening

HttpURLConnection.setFollowRedirects(true);
    con = (HttpURLConnection) new URL(url[0]).openConnection();
    con.setRequestMethod("GET");
    con.setConnectTimeout(10000);
Trinimon
  • 13,839
  • 9
  • 44
  • 60
Tarun Sharma
  • 601
  • 3
  • 13
  • 31

2 Answers2

4

I was having same problem. Looks that was due to recycling connection.

con.setRequestProperty("Connection", "close");

did the trick (Or use addHeader, if still using Apache Http)

1

Maybe OkHttp solves your problem:

http://square.github.io/okhttp/

You can try out OkHttp without rewriting your network code. The okhttp-urlconnection module implements the familiar java.net.HttpURLConnection API and the okhttp-apache module implements the Apache HttpClient API.

Note: OkHttp is standard in Android 5. So why not use it in lower versions :)

Patrick Dorn
  • 756
  • 8
  • 13