title: How to handle the situation when server is down on my android side
body: <p>Here is my doInBackground() method in which I call my makeHttpRequest() method which is in other class.</p>
  
  <pre><code> protected String doInBackground(Integer... args) {
              // Building Parameters
  
              String parameter1 = "tenant";
                  String parameter2 = "price";
  
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
  
                  params.add(new BasicNameValuePair("person",parameter1));
                          params.add(new BasicNameValuePair("price",parameter2));
  
              JSONObject json = jParser.makeHttpRequest(requiredurl, "POST", params);
  
  
              Log.d("Details", json.toString());
  
  
  
                  int success = json.getInt("connected");
  
                  if (success == 1) {
  
                      //blah blah
                        }
          }
  </code></pre>
  
  <p><strong>makeHttpRequest() method:</strong></p>
  
  <pre><code>public JSONObject makeHttpRequest(String url, String method,
              List&lt;NameValuePair&gt; params) {
  
          // Making HTTP request
          try {
  
              // check for request method
              if(method == "POST"){
  
                  // defaultHttpClient
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  HttpPost httpPost = new HttpPost(url);
                  httpPost.setEntity(new UrlEncodedFormEntity(params));
  
                  HttpResponse httpResponse = httpClient.execute(httpPost);
  
                  HttpEntity httpEntity = httpResponse.getEntity();
                  is = httpEntity.getContent();
  
              }       
  
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
         ................
         ....................... // Here the result is extracted and made it to json object
         .............................
  
          // return JSON 
          return jObj;  // returning the json object to the method that calls.
  
      }
  </code></pre>
  
  <p>So, by the above code, the actual call to the server is made by this line ->  <code>HttpResponse httpResponse = httpClient.execute(httpPost);</code> </p>
  
  <p>When my server is up everything works fine, but when it is down the progress bar continuously loads. I want to handle this situation. Have done lot of search, but could find only this <a href="https://stackoverflow.com/questions/14109473/handling-server-down-while-calling-rest-web-services">post</a>. This looks good for my situation because even my thought is to wait for the 10 seconds to get the response and if it exceeds that time out, I need to handle it to show the message in the catch block. But I am unable to implement it according to my code. Can some one please help me on this? I would be very thankful.</p>