title: HttpResponse & Timeout for Android
body: <p>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...</p>
  
  <p>Have an idea?
  Am I trying to catch the right exception?</p>
  
  <p>Thanks.</p>
  
  <pre><code>        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() &lt; 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!"); 
          }
  </code></pre>