Hello Francois,

Browsers do not respect much this part of the specifications. I remember I
made some comprehensive tests (but this was a few years ago) and most
browsers were changing POST to GET.
Le 6 févr. 2013 09:15, "COURTAULT Francois" <[email protected]>
a écrit :

> Hello Oleg,
>
> First, thanks a lot for you answer.
> Is it written in the rfc 2626 spec because I have not seen it :-(
>
> I have only seen at 10.3.2:
>         If the 301 status code is received in response to a request other
>         than GET or HEAD, the user agent MUST NOT automatically redirect
> the
>         request unless it can be confirmed by the user, since this might
>         change the conditions under which the request was issued.
>
>       Note: When automatically redirecting a POST request after
>       receiving a 301 status code, some existing HTTP/1.0 user agents
>       will erroneously change it into a GET request.
>
> So my understanding is that the default behavior for HTTP/1.1 user agent
> is to not change the HTTP request (eg keep the POST request).
> Am I wrong ?
>
> But maybe the first paragraph prevails meaning that for 301 user agent
> automatic redirection is not allowed: right ?
>
> Best Regards.
>
> -----Original Message-----
> From: Oleg Kalnichevski [mailto:[email protected]]
> Sent: mardi 5 février 2013 23:31
> To: HttpClient User Discussion
> Subject: Re: POST redirection question
>
> 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]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to