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 motital74 <mo...@gmail.com> on 2010/11/04 18:45:29 UTC
POST response with status 302 doesn't redirect
Hello
I am using httpclient 4.0.3 GA.
I am trying to connect to a website using the http client which required
POST request (https).
The response HTTP status of the POST request is 302 (the location header as
the URI).
for some reason that I don't understand the http client doesn't redirect it.
The expected result is GET METHOD with the redirect URI.
Any Idea?
--
View this message in context: http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30134484.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 motital74 <mo...@gmail.com>.
Thanks allot Ryan
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-tp30134484p30137612.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
>
>
Re: POST response with status 302 doesn't redirect
Posted by sansun08 <cs...@gmail.com>.
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 Ryan Smith <ry...@gmail.com>.
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
>
>
Re: POST response with status 302 doesn't redirect
Posted by motital74 <mo...@gmail.com>.
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
Re: POST response with status 302 doesn't redirect
Posted by Ryan Smith <ry...@gmail.com>.
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?
On Thu, Nov 4, 2010 at 2:37 PM, motital74 <mo...@gmail.com> wrote:
>
> Thank you Ryan
> I looked after RedirectStrategy as part of 4.0.3 with no luck.
> I have implemented the RedirectHandler and got the foolowing Exception:
> Exception in thread "main" java.lang.IllegalArgumentException: Host name
> may
> not be null
>
> In the getLocationURI I return the URI from the response header (Location).
>
> Appreciate your help
>
>
> Ryan Smith-10 wrote:
> >
> > Redirecting POSTs breaks RFC standards. You need to extend and implement
> > your own RedirectHandler/RedirectStrategy and tell HttpClient to use it
> > instead of the default one.
> >
> > hth.
> >
> > On Thu, Nov 4, 2010 at 1:45 PM, motital74 <mo...@gmail.com> wrote:
> >
> >>
> >> Hello
> >>
> >> I am using httpclient 4.0.3 GA.
> >> I am trying to connect to a website using the http client which required
> >> POST request (https).
> >> The response HTTP status of the POST request is 302 (the location header
> >> as
> >> the URI).
> >> for some reason that I don't understand the http client doesn't redirect
> >> it.
> >> The expected result is GET METHOD with the redirect URI.
> >> Any Idea?
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30134484.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-tp30134484p30134949.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 motital74 <mo...@gmail.com>.
Thank you Ryan
I looked after RedirectStrategy as part of 4.0.3 with no luck.
I have implemented the RedirectHandler and got the foolowing Exception:
Exception in thread "main" java.lang.IllegalArgumentException: Host name may
not be null
In the getLocationURI I return the URI from the response header (Location).
Appreciate your help
Ryan Smith-10 wrote:
>
> Redirecting POSTs breaks RFC standards. You need to extend and implement
> your own RedirectHandler/RedirectStrategy and tell HttpClient to use it
> instead of the default one.
>
> hth.
>
> On Thu, Nov 4, 2010 at 1:45 PM, motital74 <mo...@gmail.com> wrote:
>
>>
>> Hello
>>
>> I am using httpclient 4.0.3 GA.
>> I am trying to connect to a website using the http client which required
>> POST request (https).
>> The response HTTP status of the POST request is 302 (the location header
>> as
>> the URI).
>> for some reason that I don't understand the http client doesn't redirect
>> it.
>> The expected result is GET METHOD with the redirect URI.
>> Any Idea?
>> --
>> View this message in context:
>> http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30134484.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-tp30134484p30134949.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>.
Redirecting POSTs breaks RFC standards. You need to extend and implement
your own RedirectHandler/RedirectStrategy and tell HttpClient to use it
instead of the default one.
hth.
On Thu, Nov 4, 2010 at 1:45 PM, motital74 <mo...@gmail.com> wrote:
>
> Hello
>
> I am using httpclient 4.0.3 GA.
> I am trying to connect to a website using the http client which required
> POST request (https).
> The response HTTP status of the POST request is 302 (the location header as
> the URI).
> for some reason that I don't understand the http client doesn't redirect
> it.
> The expected result is GET METHOD with the redirect URI.
> Any Idea?
> --
> View this message in context:
> http://old.nabble.com/POST-response-with-status-302-doesn%27t-redirect-tp30134484p30134484.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
>
>