title: org.apache.http.NoHttpResponseException: The target server failed to respond
body: <pre><code>import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.client.utils.URLEncodedUtils;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.params.HttpProtocolParams;
  
  public class JSONParser {
  
      static InputStream is = null;
      static JSONObject jObj = null;
      static String json = "";
      private final String TAG = "ACCESS";
  
      // constructor
      public JSONParser() {
  
      }
  
      // function get json from url
      // by making HTTP POST or GET mehtod
      public JSONObject makeHttpRequest(String url, String method,
          List&lt;NameValuePair&gt; params) {
  
          // Making HTTP request
          try {
  
              // check for request method
              if(method.equals("POST")){
              // request method is 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();
  
          }else if(method.equals("GET")){
              // request method is GET
              Log.e(TAG, "check1");
              DefaultHttpClient httpClient = new DefaultHttpClient();
              Log.e(TAG, "check2");
              HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), false);
              Log.e(TAG, "check3");
              String paramString = URLEncodedUtils.format(params, "utf-8");
              Log.e(TAG, "check4");
              url += "?" + paramString;
              Log.e(TAG, "check5");
              HttpGet httpGet = new HttpGet(url);
              Log.e(TAG, "check6");
  
              HttpResponse httpResponse = httpClient.execute(httpGet); //getting exception here
              Log.e(TAG, "check7");
              HttpEntity httpEntity = httpResponse.getEntity();
              Log.e(TAG, "check8");
              is = httpEntity.getContent();
              Log.e(TAG, "check9");
          }           
  
      }
      catch (UnsupportedEncodingException e) {
  
          Log.e(TAG, "e1"+e.toString());
          return null;
      }
      catch (ClientProtocolException e) {
          Log.e(TAG, "e2"+e.toString());
          return null;
      }
      catch (IOException e) {
          Log.e(TAG, "e3"+e.toString());//this exception occurs
          return null;
      }
  
      try {
          BufferedReader reader = new BufferedReader(new InputStreamReader(
                  is, "iso-8859-1"), 8);
          StringBuilder sb = new StringBuilder();
          String line = null;
          while ((line = reader.readLine()) != null) {
              sb.append(line + "\n");
          }
          is.close();
          json = sb.toString();
      } catch (Exception e) {
          Log.e(TAG, "e4"+" Error converting result " + e.toString());
          return null;
      }
  
      // try parse the string to a JSON object
      try {
          jObj = new JSONObject(json);
      } catch (JSONException e) {
          Log.e(TAG, "e5"+" Error parsing data " + e.toString());
          return null;
      }
  
      // return JSON String
      return jObj;
  
    }
  }
  </code></pre>
  
  <p>When I am calling the above code with an object jParser of above class, it gives exception.<br/></p>
  
  <pre><code>private final String GET_ALL_MODEL_NAME = "http://10.0.0.2/android_connect/get_all_model_name.php";
  
  List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
  
  // getting JSON string from URL
  JSONObject json = jParser.makeHttpRequest(GET_ALL_MODEL_NAME, "GET", params);
  </code></pre>
  
  <p>I am getting the exception. my logcat is</p>
  
  <p>02-23 03:52:55.702: E/ACCESS(1603): check1<br/>
  02-23 03:52:55.732: E/ACCESS(1603): check2<br/>
  02-23 03:52:55.732: E/ACCESS(1603): check3<br/>
  02-23 03:52:55.742: E/ACCESS(1603): check4<br/>
  02-23 03:52:55.742: E/ACCESS(1603): check5<br/>
  02-23 03:52:55.792: E/ACCESS(1603): check6<br/>
  02-23 03:56:22.442: E/ACCESS(1603): e3org.apache.http.NoHttpResponseException: The target server failed to respond<br/></p>
  
  <p>Please help, as I googled but find nothing helpful</p>