Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache HttpComponents HttpClient timeout

How do I set the connection timeout in httpcomponents httpclient? I have found the documentation at: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html but it is not clear how these parameters are actually set.

Also, an explanation of the difference between SO_TIMEOUT and CONNECTION_TIMEOUT would be helpful.

like image 895
Landon Kuhn Avatar asked May 16 '11 23:05

Landon Kuhn


People also ask

How do I set HttpClient timeout?

To set an infinite timeout, set the property value to InfiniteTimeSpan. A Domain Name System (DNS) query may take up to 15 seconds to return or time out.

What is connection timeout in HttpClient?

timeout) – the time waiting for data – after establishing the connection; maximum time of inactivity between two data packets. the Connection Manager Timeout (http. connection-manager. timeout) – the time to wait for a connection from the connection manager/pool.

What is default HttpClient timeout?

The default timeout of an HttpClient is 100 seconds.

What is connection request timeout?

request timeout — a time period required to process an HTTP call: from sending a request to receiving a response. connection timeout — a time period in which a client should establish a connection with a server. socket timeout — a maximum time of inactivity between two data packets when exchanging data with a server.


1 Answers

In version 4.3 of Apache Http Client the configuration was refactored (again). The new way looks like this:

RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder.setConnectTimeout(timeout); requestBuilder.setConnectionRequestTimeout(timeout);  HttpClientBuilder builder = HttpClientBuilder.create();      builder.setDefaultRequestConfig(requestBuilder.build()); HttpClient client = builder.build(); 
like image 123
30thh Avatar answered Oct 07 '22 01:10

30thh