On Fri, 2011-07-29 at 10:54 +0200, Julien Vermillard wrote:
> Hi !
> I'm using the async http client for post & get methods, it's working
> fine until now.
>
> here my code :
>
> <code>
> clientMethod = new HttpAsyncPost(targetUrl, content,
> request.getContentType());
>
> httpclient.execute(clientMethod, new MyResponseConsumer(continuation),
> new FutureCallback<Boolean>() {
> ...
> </code>
>
> I would like to add header value in my requests, but I'm unable to
> find the way to do it in the API.
> Where I'm supposed to add my headers ?
>
> Julien
>
Hi Julien
If you do not mind upgrading to the snapshot, you can use the
HttpAsyncMethods#create() method to create an async producer from an
arbitrary HttpRequest instance.
http://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java
With 4.0a2 you will have to override the HttpAsyncPost#createRequest
method in order to add custom headers to the request (which is clumsy).
Alternatively, you might want to use a protocol interceptor in order to
add custom headers to all outgoing requests. Protocol interceptors is
the recommended way of dealing with cross-cutting aspects of the HTTP
protocol in HttpCore.
Hope this helps
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]