You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Daniel Holm <da...@gmail.com> on 2011/07/21 14:53:09 UTC
Issue with replacing default header value
Hello everyone!
I'm trying to replace the value of some of my default headers on a per
request basis, but I'm not sure how to do this.
I'm setting the default headers on the client using :
client.getParams().setParameter(ClientPNames.DEFAULT_HEADERS, headers);
On some requests I need to replace the value of some of the default headers,
I do this like so:
request.setHeader(HttpHeaders.ACCEPT, "application/json");
When executing the request it has duplicate headers, one with the default
value and one with the new value. I would rather want to replace the default
value with the new one, how do I do this?
/Daniel
Re: Issue with replacing default header value
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2011-07-21 at 14:53 +0200, Daniel Holm wrote:
> Hello everyone!
> I'm trying to replace the value of some of my default headers on a per
> request basis, but I'm not sure how to do this.
>
> I'm setting the default headers on the client using :
>
> client.getParams().setParameter(ClientPNames.DEFAULT_HEADERS, headers);
>
> On some requests I need to replace the value of some of the default headers,
> I do this like so:
>
> request.setHeader(HttpHeaders.ACCEPT, "application/json");
>
> When executing the request it has duplicate headers, one with the default
> value and one with the new value. I would rather want to replace the default
> value with the new one, how do I do this?
>
> /Daniel
Daniel
The RequestDefaultHeaders protocol interceptor only adds fields but
never replaces those that are already there.
http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
You need to remove the RequestDefaultHeaders interceptor and replace it
with a custom one if you want default headers to be handled differently.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org