You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Ryan Smith <ry...@gmail.com> on 2010/10/13 05:47:50 UTC

How to get POST redirects into a GET request.

Hello,

I am using HttpClient 4.1-alpha2 and I am coming across a web server that
takes a POST method request, but sends back a 302 temp redirect.

After checking the DefaultRedirectStrategy code, line 83,  I noticed that
POSTs wont redirect. (probably breaks an RFC?)

        switch (statusCode) {
        case HttpStatus.SC_MOVED_TEMPORARILY:
            return (method.equalsIgnoreCase(HttpGet.METHOD_NAME)
                || method.equalsIgnoreCase(HttpHead.METHOD_NAME)) &&
locationHeader != null;

So since Firefox, MSIE, etc take redirects from a POST and do a GET on the
redirected location uri, how would I go about doing that in HttpClient?  I
figured I'd ask here before hacking & patching.

Thank you.

-Ryan

Re: How to get POST redirects into a GET request.

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2010-10-13 at 00:09 -0400, Ryan Smith wrote:
> Ok, ill try to answer my own question.  Yes, its against the the RFCs,
> 
>  http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
> 
> Note: RFC 1945 and RFC 2068 specify that the client is not allowed
>       to change the method on the redirected request
> 
> So I just overrode the isRedirect() method and returned True when a POST and
> a redirect were happening and everything works fine.
> 
> -Ryan
> 

Yep, custom RedirectStrategy implementations can relax pretty much any
restriction on redirect handling imposed by the HTTP spec.

Cheers

Oleg

> 
> On Tue, Oct 12, 2010 at 11:47 PM, Ryan Smith <ry...@gmail.com>wrote:
> 
> > Hello,
> >
> > I am using HttpClient 4.1-alpha2 and I am coming across a web server that
> > takes a POST method request, but sends back a 302 temp redirect.
> >
> > After checking the DefaultRedirectStrategy code, line 83,  I noticed that
> > POSTs wont redirect. (probably breaks an RFC?)
> >
> >         switch (statusCode) {
> >         case HttpStatus.SC_MOVED_TEMPORARILY:
> >             return (method.equalsIgnoreCase(HttpGet.METHOD_NAME)
> >                 || method.equalsIgnoreCase(HttpHead.METHOD_NAME)) &&
> > locationHeader != null;
> >
> > So since Firefox, MSIE, etc take redirects from a POST and do a GET on the
> > redirected location uri, how would I go about doing that in HttpClient?  I
> > figured I'd ask here before hacking & patching.
> >
> > Thank you.
> >
> > -Ryan
> >
> >
> >



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: How to get POST redirects into a GET request.

Posted by Ryan Smith <ry...@gmail.com>.
Ok, ill try to answer my own question.  Yes, its against the the RFCs,

 http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Note: RFC 1945 and RFC 2068 specify that the client is not allowed
      to change the method on the redirected request

So I just overrode the isRedirect() method and returned True when a POST and
a redirect were happening and everything works fine.

-Ryan


On Tue, Oct 12, 2010 at 11:47 PM, Ryan Smith <ry...@gmail.com>wrote:

> Hello,
>
> I am using HttpClient 4.1-alpha2 and I am coming across a web server that
> takes a POST method request, but sends back a 302 temp redirect.
>
> After checking the DefaultRedirectStrategy code, line 83,  I noticed that
> POSTs wont redirect. (probably breaks an RFC?)
>
>         switch (statusCode) {
>         case HttpStatus.SC_MOVED_TEMPORARILY:
>             return (method.equalsIgnoreCase(HttpGet.METHOD_NAME)
>                 || method.equalsIgnoreCase(HttpHead.METHOD_NAME)) &&
> locationHeader != null;
>
> So since Firefox, MSIE, etc take redirects from a POST and do a GET on the
> redirected location uri, how would I go about doing that in HttpClient?  I
> figured I'd ask here before hacking & patching.
>
> Thank you.
>
> -Ryan
>
>
>