On 5/16/2018 8:09 AM, / wrote:
I am looking for an example on how to configure HttpClient5 after it has been built and how to extract/print some of its configuration.

Once I have an HttpClient object, how do I go about and change some of its settings, for example connection timeout or user-agent-string or even cookie jar?

I am looking for the most straight-forward and efficient way to do this. I don't care about "fluent" APIs neither about streams etc.

something like:

myclient.setParameter(connection_timeout, 1000);

For the most part, you can't change settings on an existing HttpClient object.  Since about 4.3, the objects and methods that allow clients to be changed after creation are all deprecated. That capability is completely gone in 5.x.  Default settings are managed with builder objects using fluent methods, then you create the client object with the indicated settings.  Here's how I create a client object with explicit defaults using non-deprecated code in the 4.5 version:

  RequestConfig rc = RequestConfig.custom().setConnectTimeout(15000)
          .setSocketTimeout(120000).build();
  httpClient = HttpClients.custom().setDefaultRequestConfig(rc)
.setMaxConnPerRoute(300).setMaxConnTotal(5000).disableAutomaticRetries()
          .build();

The httpClient field is an instance of HttpClient.  I do not know what kind of adjustments might need to be made for 5.x, but that should give you an idea about how things are done since the way you're trying to do it is no longer available.

Many of the settings you might be interested in can also be changed at the request level.  I do not know HOW to do this, only that it CAN be done.  I think this is what Oleg was referring to in his reply.

Thanks,
Shawn


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to