Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Keep Alive in Apache HttpClient

For some problem that we couldn't solve, I want to disable keep alive on Apache HttpClient 3.1. However, I couldn't find any resource on the Internet for that. Do you know how to do it?

like image 801
cacert Avatar asked May 29 '13 07:05

cacert


People also ask

What is keep alive strategy HttpClient?

HTTP keep-alive, a.k.a., HTTP persistent connection, is an instruction that allows a single TCP connection to remain open for multiple HTTP requests/responses. By default, HTTP connections close after each request.

Does HttpClient need to be closed?

You do not need to explicitly close the HttpClient, however, (you may be doing this already but worth noting) you should ensure that connections are released after method execution. Edit: The ClientConnectionManager within the HttpClient is going to be responsible for maintaining the state of connections.

What is setMaxPerRoute?

setMaxPerRoute(int max) – Set the total number of concurrent connections to a specific route, which is two by default.


1 Answers

You can disable HTTP 1.1 support on you method, i.e. httpMethod.setHttp11(false); but you will lost some other features.

You can also try to force the connection header to ask the server to close the connection after its response: httpMethod.setRequestHeader("Connection", "close").

like image 96
gma Avatar answered Sep 29 '22 14:09

gma