On Tue, 2013-02-05 at 18:53 +0100, COURTAULT Francois wrote:
> Hello everyone,
>
> At the beginning, I had something like that :
> HttpClient httpClient = new DefaultHttpClient();
> HttpPost httpPost = new HttpPost(SOME_URL);
> HttpResponse postResponse = httpClient.execute(httpPost);
>
> It turns out that I got a 301 Moved permanently.
>
> So I made the following modifications, either:
> - httpClient.setRedirectStrategy(new LaxRedirectStrategy());
> - or httpClient.setRedirectStrategy(new DefaultRedirectStrategy());
> - or httpClient.setRedirectStrategy(new
> DefaultRedirectStrategy() {
> @Override
> public boolean isRedirected(HttpRequest request,
> HttpResponse response, HttpContext context) {
> boolean isRedirected = false;
> try {
> isRedirected = super.isRedirected(request,
> response, context);
> } catch (ProtocolException e) {
> fail("Unable to set a redirect strategy,
> reason: " + e.getMessage());
> }
>
> if (!isRedirected) {
> int responseCode =
> response.getStatusLine().getStatusCode();
> if (responseCode == 301 || responseCode == 302)
> {
> return true;
> }
> }
> return false;
> }
> });
> - or the same than above with new LaxRedirectStrategy
>
> Each time, after receiving a 301, the client sent a GET request instead of my
> initial HTTP request, which is a POST one as you can see, to the new location.
> Any advice ? sample ?
> Or is it an issue ?
>
> Best Regards.
Only in case of a TEMPORARY_REDIRECT it is valid to redirect the request
without changing its method. In all other cases methods other than HEAD
and GET get converted to GET. To change this behavior you need to
override #getRedirect method
http://hc.apache.org/httpcomponents-client-ga/httpclient/xref/org/apache/http/impl/client/DefaultRedirectStrategy.html#213
Oleg
> ---------------------------------------------------------------------
> 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]