How to solve org.apache.http.NoHttpResponseException

前端 未结 2 1644
名媛妹妹
名媛妹妹 2021-02-09 23:24

I\'m using apache httpclient 4.4 to do https requests, and I can constantly to see org.apache.http.NoHttpResponseException.

Here\'s my code to create the h

相关标签:
2条回答
  • 2021-02-09 23:48

    Another way around this issue is to configure your org.apache.http.impl.client.AbstractHttpClient httpClient to never reuse connections:

    httpClient.setReuseStrategy(new NoConnectionReuseStrategy());
    

    The same can be configured on a org.apache.http.impl.client.HttpClientBuilder builder:

    builder.setConnectionReuseStrategy(new NoConnectionReuseStrategy());
    
    0 讨论(0)
  • 2021-02-10 00:03

    Finally figured it out on my own. If the previous response gives header, "connections=close", next request always gets this exception. So, when seeing this header, put 2 more lines

    conManager.closeExpiredConnections();
    conManager.closeIdleConnections(0, TimeUnit.SECONDS);
    

    to let connection manager close the connection so that the connection won't be used by the next request.

    0 讨论(0)
提交回复
热议问题