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]