Oleg,
Is there a better place in HttpPost or HttpClient to modify post form
parameters or should they just be modified before HttpPost or HttpClient
? That sounds like a dumb question, but I like the idea of an
interceptor to modify the request before it gets sent.
Thanks,
Warren Bell
On 2/13/12 8:25 AM, Oleg Kalnichevski wrote:
> On Sun, Feb 12, 2012 at 12:11:04PM -0800, Warren Bell wrote:
>> How do I write a request interceptor that removes, modifies or adds post
>> parameters to the request? Everything I have tried so far throws
>> exceptions that state you are not able to add a parameter at this point.
>>
>
> I am not entirely sure it is a good idea to modify request uris from an
> interceptor, but this is how you could do it.
>
> ---
> DefaultHttpClient httpclient = new DefaultHttpClient();
> httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
>
> public void process(
> final HttpRequest request,
> final HttpContext context) throws HttpException, IOException {
> RequestWrapper wrapper = (RequestWrapper) request;
> URIBuilder uribuilder = new URIBuilder(wrapper.getURI());
> uribuilder.setParameter("myparam", "stuff");
> try {
> wrapper.setURI(uribuilder.build());
> } catch (URISyntaxException ex) {
> throw new HttpException("Invalid request URI", ex);
> }
> }
> });
> HttpResponse response = httpclient.execute(new HttpGet("http://somehost/"));
> EntityUtils.consumeQuietly(response.getEntity());
> ---
>
> Oleg
>
>
>
>> --
>> Thanks,
>>
>> Warren Bell
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]