I have a problem with request POST/GET in Android.
I am trying to handle the error:
Caused by: java.net.SocketTimeoutException: Read timed out
To prevent the crash on my application, I added a timeout of 40 seconds. That works but sometimes 40 seconds is not enough to avoid the error.
I tried to add the “try and catch” but it seems that the error isn’t occurring inside here:
try {
request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
localContext.setAttribute(ClientContext.COOKIE_STORE,
Backend2.cookieStore);
response = HttpManager.execute(request, localContext);
if (response.getEntity() != null) {
final String r = EntityUtils.toString(response.getEntity());
return r;
} else {
return null;
}
} catch (SocketTimeoutException e) {
e.printStackTrace();
return null;
} catch (UnknownHostException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
I am looking for a solution but when I read on stackoverflow and on google, I see only posts like “increase your timeout, add a try, etc..”
I am doing something wrong?
It’s hard to tell just looking at your catch statement, but maybe you are getting a different error than a SocketTimeoutException? Try to catch an Exception instead to confirm that.