I want my device to give up the http connexion after 5 seconds. But my code does not work... I never get any timeout message when shutting network down. Just like if the device still tries to connect, despite de timeout...
Have an idea? Am I trying to catch the right exception?
Thanks.
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() < 400)
{
... //data processing
}
else
{
errorMsgId = R.string.http_site_error;
}
}
catch (ConnectTimeoutException e)
{
Toast.makeText(this, "Network timeout reached!", Toast.LENGTH_SHORT).show();
Log.e("+++++++++++++++++ ","Network timeout reached!");
}