For example the default user agent could be set like:
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, someName);
But how to set the "Accept" header?
-
Did you mean in the code level or in Apache configuration ? httpd.apache.org/docs/2.2/content-negotiation.htmlNir Alfasi– Nir Alfasi2013-09-09 22:00:29 +00:00Commented Sep 9, 2013 at 22:00
-
I meant the httpclient library, not Apache server.NSF– NSF2013-09-09 22:13:40 +00:00Commented Sep 9, 2013 at 22:13
Add a comment
|
1 Answer
HttpClient 4.3 now allows configuring a collection of default headers on the client itself:
Header header = new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json");
List<Header> headers = Lists.newArrayList(header);
HttpClient client = HttpClients.custom().setDefaultHeaders(headers).build();
HttpUriRequest request = RequestBuilder.get().setUri(SAMPLE_URL).build();
client.execute(request);
Now, all requests executed by that client will be send with the default headers. Hope that helps.