title: HttpClientError: The target server failed to respond
body: <p>I am trying to hit a server using HTTP client using <code>PoolingClientConnectionManager</code> setting max connections for individual hosts</p>
  <pre class="lang-java prettyprint-override"><code>//Code that initializes my connection manager and HTTP client 
  HttpParams httpParam = httpclient.getParams();
  HttpConnectionParams.setSoTimeout(httpParam, SOCKET_TIMEOUT);
  
  HttpConnectionParams.setConnectionTimeout(httpParam, CONN_TIMEOUT);
  
  httpclient.setParams(httpParam);
  
  //Run a thread which closes Expired connections
  new ConnectionManager(connManager).start(); 
  
  //Code that executes my request 
  HttpPost httpPost = new HttpPost(url);
          HttpEntity httpEntity = new StringEntity(request, &quot;UTF-8&quot;);
  httpPost.setEntity(httpEntity);
  
  Header acceptEncoding = new BasicHeader(&quot;Accept-Encoding&quot;, &quot;gzip,deflate&quot;);
  httpPost.setHeader(acceptEncoding);     
  
  if(contenttype != null &amp;&amp; !contenttype.equals(&quot;&quot;)){
      Header contentType = new BasicHeader(&quot;Content-Type&quot;, contenttype);
      httpPost.setHeader(contentType);
  }
  InputStream inputStream = null;
  LOG.info(dataSource + URL + url + REQUEST + request);
  
  HttpResponse response = httpclient.execute(httpPost);
  </code></pre>
  <p>That is we are using Connection pooling for http persistence .</p>
  <p>We are getting this error sporadically :</p>
  <pre><code>The target server failed to respond
  org.apache.http.NoHttpResponseException: The target server failed to respond
          at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:95)
          at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62)
          at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
          at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
          at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
          at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
          at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
          at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
          at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:517)
          at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
  </code></pre>
  <p>Does any one know how to resolve this?</p>
  <p>We are shutting down idle connections as well.</p>
  <p>Can some Please help.</p>
  <p><a href="http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html" rel="noreferrer">http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html</a></p>