I am encountering some problems with the HttpUrlConnection in devices running Jellybean (4.1 - 4.3) wherein connections are not closed and results to a SocketException \"Too
Check If you have tried all of the below... There might be something missing.. other wise it should not have any problem.
InputStream in;
HttpsURLConnection urlConnection =null;
try {
URL url = new URL(Url);
urlConnection = (HttpsURLConnection) url
.openConnection();
//5 Second timeout
urlConnection.setReadTimeout(5*1000);
in = urlConnection.getInputStream();
int responseCode = urlConnection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
InputStream errInputStream = urlConnection.getErrorStream();
//Print error message and response code..
errInputStream.close();
}
in.close();
} catch (Exception e) {
e.printStackTrace();
} finally{
if(urlConnection != null)
urlConnection.disconnect();
}