¿Cómo establecer el encabezado predeterminado para todas las solicitudes en el cliente http de apache?
Frecuentes
Visto 14,631 veces
12
For example the default user agent could be set like:
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, someName);
But how to set the "Accept" header?
1 Respuestas
24
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.
Respondido el 25 de enero de 14 a las 15:01
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas java httpclient or haz tu propia pregunta.
Did you mean in the code level or in Apache configuration ? httpd.apache.org/docs/2.2/content-negotiation.html - Nir Alfasi
I meant the httpclient library, not Apache server. - NSF