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 sansun08 <cs...@gmail.com> on 2010/12/09 11:22:44 UTC

Re: POST response with status 302 doesn't redirect

I am having the same problem. Thanks for your answer. But how can I associate
this custom RedirectStratergy to  the httpclient instance. There are no
methods available to do that.

Thanks
Sankar


Ryan Smith-10 wrote:
> 
> DefaultRedirectStrategy is in 4.1-alpha2.  Youre using 4.0.3 so it has
> RedirectHandler.  Anywho you dont need to override the getLocationUrl().
> You want to override the isRedirectRequested()
> 
> http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/DefaultRedirectHandler.html
> 
> hth
> 
> On Thu, Nov 4, 2010 at 3:11 PM, motital74 <mo...@gmail.com> wrote:
> 
>>
>> Ryan, thanks again
>>
>> I can find the DefaultRedirectStrategy as part of the GA.
>>
>> I did implement the handler:
>> public URI getLocationURI(HttpResponse httpResponse, HttpContext
>> httpContext) throws ProtocolException {
>>               
>> System.out.println("=======================getLocationURI");
>>                Header[] headers = httpResponse.getHeaders("Location");
>>                if (headers != null && headers.length > 0) {
>>                    try {
>>                        System.out.println(""==============getLocationURI
>> return" + headers[0].getValue());
>>                        return new URI(headers[0].getValue());
>>                    } catch (URISyntaxException e) {
>>                        e.printStackTrace();
>>                    }
>>                }
>>                System.out.println("=======================getLocationURI
>> return null");
>>                return null;
>>            }
>>
>> In my case i see the return log with the correct URI
>>
>>
>> Ryan Smith-10 wrote:
>> >
>> > I am using 4.1-alpha2, in this version, you extend
>> DefaultRedirectStrategy
>> > and override the method isRedirected().  Inside that method, check for
>> a
>> > post method and a 302 or 301 and return true if so.  I use something
>> like
>> > this:
>> >
>> >   boolean isRedirect = super.isRedirected(request, response, context);
>> >   if (!isRedirect) {
>> >         //  Then check for POST and 302 or 301.
>> >
>> > Maybe post your code?
>> >
>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30135246.html
>> Sent from the HttpClient-User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30414709.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: POST response with status 302 doesn't redirect

Posted by sansun08 <cs...@gmail.com>.
Thanks a lot Ryan. I somehow overlooked this.

Sankar

Ryan Smith-10 wrote:
> 
> Hello Sankar,
> 
> HttpClient classes in 4.1.x have a setRedirectStrategy() method that you
> use
> to set with your custom redirect strategy.
> 
> hth
> 
> 
> 
> On Thu, Dec 9, 2010 at 5:22 AM, sansun08
> <cs...@gmail.com>wrote:
> 
>>
>> I am having the same problem. Thanks for your answer. But how can I
>> associate
>> this custom RedirectStratergy to  the httpclient instance. There are no
>> methods available to do that.
>>
>> Thanks
>> Sankar
>>
>>
>> Ryan Smith-10 wrote:
>> >
>> > DefaultRedirectStrategy is in 4.1-alpha2.  Youre using 4.0.3 so it has
>> > RedirectHandler.  Anywho you dont need to override the
>> getLocationUrl().
>> > You want to override the isRedirectRequested()
>> >
>> >
>> http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/DefaultRedirectHandler.html
>> >
>> > hth
>> >
>> > On Thu, Nov 4, 2010 at 3:11 PM, motital74 <mo...@gmail.com> wrote:
>> >
>> >>
>> >> Ryan, thanks again
>> >>
>> >> I can find the DefaultRedirectStrategy as part of the GA.
>> >>
>> >> I did implement the handler:
>> >> public URI getLocationURI(HttpResponse httpResponse, HttpContext
>> >> httpContext) throws ProtocolException {
>> >>
>> >> System.out.println("=======================getLocationURI");
>> >>                Header[] headers = httpResponse.getHeaders("Location");
>> >>                if (headers != null && headers.length > 0) {
>> >>                    try {
>> >>                       
>> System.out.println(""==============getLocationURI
>> >> return" + headers[0].getValue());
>> >>                        return new URI(headers[0].getValue());
>> >>                    } catch (URISyntaxException e) {
>> >>                        e.printStackTrace();
>> >>                    }
>> >>                }
>> >>               
>> System.out.println("=======================getLocationURI
>> >> return null");
>> >>                return null;
>> >>            }
>> >>
>> >> In my case i see the return log with the correct URI
>> >>
>> >>
>> >> Ryan Smith-10 wrote:
>> >> >
>> >> > I am using 4.1-alpha2, in this version, you extend
>> >> DefaultRedirectStrategy
>> >> > and override the method isRedirected().  Inside that method, check
>> for
>> >> a
>> >> > post method and a 302 or 301 and return true if so.  I use something
>> >> like
>> >> > this:
>> >> >
>> >> >   boolean isRedirect = super.isRedirected(request, response,
>> context);
>> >> >   if (!isRedirect) {
>> >> >         //  Then check for POST and 302 or 301.
>> >> >
>> >> > Maybe post your code?
>> >> >
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30135246.html
>> >> Sent from the HttpClient-User mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30414709.html
>> Sent from the HttpClient-User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30416437.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: POST response with status 302 doesn't redirect

Posted by Ryan Smith <ry...@gmail.com>.
Hello Sankar,

HttpClient classes in 4.1.x have a setRedirectStrategy() method that you use
to set with your custom redirect strategy.

hth



On Thu, Dec 9, 2010 at 5:22 AM, sansun08 <cs...@gmail.com>wrote:

>
> I am having the same problem. Thanks for your answer. But how can I
> associate
> this custom RedirectStratergy to  the httpclient instance. There are no
> methods available to do that.
>
> Thanks
> Sankar
>
>
> Ryan Smith-10 wrote:
> >
> > DefaultRedirectStrategy is in 4.1-alpha2.  Youre using 4.0.3 so it has
> > RedirectHandler.  Anywho you dont need to override the getLocationUrl().
> > You want to override the isRedirectRequested()
> >
> >
> http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/DefaultRedirectHandler.html
> >
> > hth
> >
> > On Thu, Nov 4, 2010 at 3:11 PM, motital74 <mo...@gmail.com> wrote:
> >
> >>
> >> Ryan, thanks again
> >>
> >> I can find the DefaultRedirectStrategy as part of the GA.
> >>
> >> I did implement the handler:
> >> public URI getLocationURI(HttpResponse httpResponse, HttpContext
> >> httpContext) throws ProtocolException {
> >>
> >> System.out.println("=======================getLocationURI");
> >>                Header[] headers = httpResponse.getHeaders("Location");
> >>                if (headers != null && headers.length > 0) {
> >>                    try {
> >>                        System.out.println(""==============getLocationURI
> >> return" + headers[0].getValue());
> >>                        return new URI(headers[0].getValue());
> >>                    } catch (URISyntaxException e) {
> >>                        e.printStackTrace();
> >>                    }
> >>                }
> >>                System.out.println("=======================getLocationURI
> >> return null");
> >>                return null;
> >>            }
> >>
> >> In my case i see the return log with the correct URI
> >>
> >>
> >> Ryan Smith-10 wrote:
> >> >
> >> > I am using 4.1-alpha2, in this version, you extend
> >> DefaultRedirectStrategy
> >> > and override the method isRedirected().  Inside that method, check for
> >> a
> >> > post method and a 302 or 301 and return true if so.  I use something
> >> like
> >> > this:
> >> >
> >> >   boolean isRedirect = super.isRedirected(request, response, context);
> >> >   if (!isRedirect) {
> >> >         //  Then check for POST and 302 or 301.
> >> >
> >> > Maybe post your code?
> >> >
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30135246.html
> >> Sent from the HttpClient-User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30414709.html
> Sent from the HttpClient-User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>