views:

250

answers:

2

With HttpClient, I am setting the default socket/connection timeout with the following:

HttpParams params = new BasicHttpParams();

HttpConnectionParams.setSoTimeout(params, 30000);
HttpConnectionParams.setConnectionTimeout(params, 30000);

mClient = new DefaultHttpClient(connectionManager, params);

I'm wondering if I can override these values on a per request basis?

Edit: Would this work?

HttpParams params = req.getParams(); // req is an HttpRequest object
HttpConnectionParams.setSoTimeout(params, 60000);
HttpConnectionParams.setConnectionTimeout(params, 60000);

I tried it, and it seems to, but it's hard to test/create a situation where a timeout will occur.

+2  A: 

If you are using HttpClient 4.0 you could do this :

mClient = new DefaultHttpClient(connectionManager, params) {
  protected HttpParams determineParams(HttpRequest req) {
    //Fill in your impl here
 }
A: 

You can simply set those parameters on the request object. For details see: http://hc.apache.org/httpcomponents-client-4.0.1/tutorial/html/fundamentals.html#d4e316

oleg
Looks like the URL is now: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e391
Dustin