You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Santos <js...@criticalsoftware.com> on 2003/08/26 15:16:34 UTC

[HttpClient] setFollowRedirects(true) on PostMethod

Hi all,

I writing to ask you if there's any chance to setFollowRedirects(true)
to an instance of PostMethod. I've read in the source that "Entity
enclosing requests cannot be redirected without user intervention", but
I really need a way to get around this limitation. I know that this is
probably due to the HTTP POST spec itself, but I need to invoke an HTTP
POST that performs redirection.

Thank you,
<§@nTº$ />




Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by "Sean W. Ferguson" <se...@comcast.net>.
Plus EntityEnclosingMethod hasn't changed in a while, so you should be ok.

Santos wrote:

> ok, so I will replace
> 
>  public void setFollowRedirects(boolean followRedirects) {
>         if (followRedirects == true) {
>             // TODO: EntityEnclosingMethod should inherit from
> HttpMethodBase rather than GetMethod
>             // Enable exception once the inheritence is fixed
>             //throw new IllegalArgumentException(
>             //  "Entity enclosing requests cannot be redirected without
> user intervention");
>         }
>         super.setFollowRedirects(false);
>     }
> 
> by 
> 
>  public void setFollowRedirects(boolean followRedirects) {
>         super.setFollowRedirects(false);
> }
> 
> of course I won't be able to use future releases that do not allow this
> (like some of the already existent nighly builds) :-(
> 
> thank you very much indeed.
> 
> <§@nTº$ />
> 
> 
> On Tue, 2003-08-26 at 17:37, Sean W. Ferguson wrote:
> 
>>Just do as I did, and comment out the line of code that doesn't let you set it 
>>to true.  :)
>>
>>Santos wrote:
>>
>>>Hi all,
>>>
>>>I writing to ask you if there's any chance to setFollowRedirects(true)
>>>to an instance of PostMethod. I've read in the source that "Entity
>>>enclosing requests cannot be redirected without user intervention", but
>>>I really need a way to get around this limitation. I know that this is
>>>probably due to the HTTP POST spec itself, but I need to invoke an HTTP
>>>POST that performs redirection.
>>>
>>>Thank you,
>>><§@nTº$ />
>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by Santos <js...@criticalsoftware.com>.
sorry, i meant 

public void setFollowRedirects(boolean followRedirects) {
        super.setFollowRedirects(followRedirects);
}

in my last email.

<§@nTº$ />

On Tue, 2003-08-26 at 20:08, Santos wrote:
> ok, so I will replace
> 
>  public void setFollowRedirects(boolean followRedirects) {
>         if (followRedirects == true) {
>             // TODO: EntityEnclosingMethod should inherit from
> HttpMethodBase rather than GetMethod
>             // Enable exception once the inheritence is fixed
>             //throw new IllegalArgumentException(
>             //  "Entity enclosing requests cannot be redirected without
> user intervention");
>         }
>         super.setFollowRedirects(false);
>     }
> 
> by 
> 
>  public void setFollowRedirects(boolean followRedirects) {
>         super.setFollowRedirects(false);
> }
> 
> of course I won't be able to use future releases that do not allow this
> (like some of the already existent nighly builds) :-(
> 
> thank you very much indeed.
> 
> <§@nTº$ />
> 
> 
> On Tue, 2003-08-26 at 17:37, Sean W. Ferguson wrote:
> > Just do as I did, and comment out the line of code that doesn't let you set it 
> > to true.  :)
> > 
> > Santos wrote:
> > > Hi all,
> > > 
> > > I writing to ask you if there's any chance to setFollowRedirects(true)
> > > to an instance of PostMethod. I've read in the source that "Entity
> > > enclosing requests cannot be redirected without user intervention", but
> > > I really need a way to get around this limitation. I know that this is
> > > probably due to the HTTP POST spec itself, but I need to invoke an HTTP
> > > POST that performs redirection.
> > > 
> > > Thank you,
> > > <§@nTº$ />
> > > 
> > > 
> > > 
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > > 
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> 



Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by "Sean W. Ferguson" <se...@comcast.net>.
Yes, you make that change in EntityEnclosingMethod.  If there are changes, just 
do a merge and you should be fine.  :)

Santos wrote:
> ok, so I will replace
> 
>  public void setFollowRedirects(boolean followRedirects) {
>         if (followRedirects == true) {
>             // TODO: EntityEnclosingMethod should inherit from
> HttpMethodBase rather than GetMethod
>             // Enable exception once the inheritence is fixed
>             //throw new IllegalArgumentException(
>             //  "Entity enclosing requests cannot be redirected without
> user intervention");
>         }
>         super.setFollowRedirects(false);
>     }
> 
> by 
> 
>  public void setFollowRedirects(boolean followRedirects) {
>         super.setFollowRedirects(false);
> }
> 
> of course I won't be able to use future releases that do not allow this
> (like some of the already existent nighly builds) :-(
> 
> thank you very much indeed.
> 
> <§@nTº$ />
> 
> 
> On Tue, 2003-08-26 at 17:37, Sean W. Ferguson wrote:
> 
>>Just do as I did, and comment out the line of code that doesn't let you set it 
>>to true.  :)
>>
>>Santos wrote:
>>
>>>Hi all,
>>>
>>>I writing to ask you if there's any chance to setFollowRedirects(true)
>>>to an instance of PostMethod. I've read in the source that "Entity
>>>enclosing requests cannot be redirected without user intervention", but
>>>I really need a way to get around this limitation. I know that this is
>>>probably due to the HTTP POST spec itself, but I need to invoke an HTTP
>>>POST that performs redirection.
>>>
>>>Thank you,
>>><§@nTº$ />
>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by Santos <js...@criticalsoftware.com>.
ok, so I will replace

 public void setFollowRedirects(boolean followRedirects) {
        if (followRedirects == true) {
            // TODO: EntityEnclosingMethod should inherit from
HttpMethodBase rather than GetMethod
            // Enable exception once the inheritence is fixed
            //throw new IllegalArgumentException(
            //  "Entity enclosing requests cannot be redirected without
user intervention");
        }
        super.setFollowRedirects(false);
    }

by 

 public void setFollowRedirects(boolean followRedirects) {
        super.setFollowRedirects(false);
}

of course I won't be able to use future releases that do not allow this
(like some of the already existent nighly builds) :-(

thank you very much indeed.

<§@nTº$ />


On Tue, 2003-08-26 at 17:37, Sean W. Ferguson wrote:
> Just do as I did, and comment out the line of code that doesn't let you set it 
> to true.  :)
> 
> Santos wrote:
> > Hi all,
> > 
> > I writing to ask you if there's any chance to setFollowRedirects(true)
> > to an instance of PostMethod. I've read in the source that "Entity
> > enclosing requests cannot be redirected without user intervention", but
> > I really need a way to get around this limitation. I know that this is
> > probably due to the HTTP POST spec itself, but I need to invoke an HTTP
> > POST that performs redirection.
> > 
> > Thank you,
> > <§@nTº$ />
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 



Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by "Sean W. Ferguson" <se...@comcast.net>.
Just do as I did, and comment out the line of code that doesn't let you set it 
to true.  :)

Santos wrote:
> Hi all,
> 
> I writing to ask you if there's any chance to setFollowRedirects(true)
> to an instance of PostMethod. I've read in the source that "Entity
> enclosing requests cannot be redirected without user intervention", but
> I really need a way to get around this limitation. I know that this is
> probably due to the HTTP POST spec itself, but I need to invoke an HTTP
> POST that performs redirection.
> 
> Thank you,
> <§@nTº$ />
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by Santos <js...@criticalsoftware.com>.
you're absolutely right, mike!

the location header, one of the response headers, contains exactly the
redirected URI.

thank you very much!
<§@nTº$ />

On Tue, 2003-08-26 at 18:49, Michael Becke wrote:
> Hi Santos,
> 
> There's no way to make PostMethod automatically redirect, other than 
> subclassing and overriding setFollowRedirects().
> 
> I question if this is what you want though.  Generally a redirect on 
> post indicates that the post succeeded and that the response is to be 
> read from the redirected page.  So you would perform a POST to 
> http://somehost/form and be redirected to http://somehost/response.  You 
> would then want to do a GET on http://somehost/response.
> 
> In either case it is also possible to handle the redirect manually by 
> checking the response code and getting the location header.
> 
> Mike
> 
> Santos wrote:
> 
> > Hi all,
> > 
> > I writing to ask you if there's any chance to setFollowRedirects(true)
> > to an instance of PostMethod. I've read in the source that "Entity
> > enclosing requests cannot be redirected without user intervention", but
> > I really need a way to get around this limitation. I know that this is
> > probably due to the HTTP POST spec itself, but I need to invoke an HTTP
> > POST that performs redirection.
> > 
> > Thank you,
> > <§@nTº$ />
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 



Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by Michael Becke <be...@u.washington.edu>.
Hi Santos,

In the case of a redirect the server sets the response header 'location' 
to the value of the new page URI.  This can be either a relative or 
absolute URI.  You can process it using something like:

String url1 = "http://...";
PostMethod httpPostMethod = new PostMethod(url1);
httpPostMethod.addParameter("...", "...");
httpClient.executeMethod(httpPostMethod);

if (**methodWasRedirected**) {

   URI redirectLocation = new URI(
     httpPostMethod.getURI(),
     httpPostMethod.getResponseHeader("location").getValue()
   );
   httpPostMethod = new PostMethod(redirectLocation);
   httpPostMethod.addParameter("...", "...");
   httpClient.executeMethod(httpPostMethod);
}

Mike


Santos wrote:
> hi mike,
> 
> i understand you perfectly and what you said makes sense. the problem is
> that, without followRedirects set to true, the URL I got from
> httpPostMethod.getURI().toString() (httpPostMethod is an instance of
> PostMethod) is the same as the one I pass to the PostMethod constructor
> while creating httpPostMethod. In other words:
> 
> String url1 = "http://...";
> PostMethod httpPostMethod = new PostMethod(url1);
> httpPostMethod.addParameter("...", "...");
> httpClient.executeMethod(httpPostMethod);
> String url2a = httpPostMethod.getURI().toString();
> 
> url1 is equal to url2, and I need to obtain the *redirected* url2.
> 
> Any tip?
> 
> Thank you again,
> <§@nTº$ />
> 
> On Tue, 2003-08-26 at 18:49, Michael Becke wrote:
> 
>>Hi Santos,
>>
>>There's no way to make PostMethod automatically redirect, other than 
>>subclassing and overriding setFollowRedirects().
>>
>>I question if this is what you want though.  Generally a redirect on 
>>post indicates that the post succeeded and that the response is to be 
>>read from the redirected page.  So you would perform a POST to 
>>http://somehost/form and be redirected to http://somehost/response.  You 
>>would then want to do a GET on http://somehost/response.
>>
>>In either case it is also possible to handle the redirect manually by 
>>checking the response code and getting the location header.
>>
>>Mike
>>
>>Santos wrote:
>>
>>
>>>Hi all,
>>>
>>>I writing to ask you if there's any chance to setFollowRedirects(true)
>>>to an instance of PostMethod. I've read in the source that "Entity
>>>enclosing requests cannot be redirected without user intervention", but
>>>I really need a way to get around this limitation. I know that this is
>>>probably due to the HTTP POST spec itself, but I need to invoke an HTTP
>>>POST that performs redirection.
>>>
>>>Thank you,
>>><§@nTº$ />
>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by Santos <js...@criticalsoftware.com>.
hi mike,

i understand you perfectly and what you said makes sense. the problem is
that, without followRedirects set to true, the URL I got from
httpPostMethod.getURI().toString() (httpPostMethod is an instance of
PostMethod) is the same as the one I pass to the PostMethod constructor
while creating httpPostMethod. In other words:

String url1 = "http://...";
PostMethod httpPostMethod = new PostMethod(url1);
httpPostMethod.addParameter("...", "...");
httpClient.executeMethod(httpPostMethod);
String url2a = httpPostMethod.getURI().toString();

url1 is equal to url2, and I need to obtain the *redirected* url2.

Any tip?

Thank you again,
<§@nTº$ />

On Tue, 2003-08-26 at 18:49, Michael Becke wrote:
> Hi Santos,
> 
> There's no way to make PostMethod automatically redirect, other than 
> subclassing and overriding setFollowRedirects().
> 
> I question if this is what you want though.  Generally a redirect on 
> post indicates that the post succeeded and that the response is to be 
> read from the redirected page.  So you would perform a POST to 
> http://somehost/form and be redirected to http://somehost/response.  You 
> would then want to do a GET on http://somehost/response.
> 
> In either case it is also possible to handle the redirect manually by 
> checking the response code and getting the location header.
> 
> Mike
> 
> Santos wrote:
> 
> > Hi all,
> > 
> > I writing to ask you if there's any chance to setFollowRedirects(true)
> > to an instance of PostMethod. I've read in the source that "Entity
> > enclosing requests cannot be redirected without user intervention", but
> > I really need a way to get around this limitation. I know that this is
> > probably due to the HTTP POST spec itself, but I need to invoke an HTTP
> > POST that performs redirection.
> > 
> > Thank you,
> > <§@nTº$ />
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 



Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by "Sean W. Ferguson" <se...@comcast.net>.
Well, I am doing a post to a servlet that just writes back data on the response. 
  No redirects or anything, and that exception gets thrown.  I'd prefer not to 
have to modify the httpclient code, but it makes no sense to me that it thinks a 
redirect is happening.

Michael Becke wrote:
> Hi Santos,
> 
> There's no way to make PostMethod automatically redirect, other than 
> subclassing and overriding setFollowRedirects().
> 
> I question if this is what you want though.  Generally a redirect on 
> post indicates that the post succeeded and that the response is to be 
> read from the redirected page.  So you would perform a POST to 
> http://somehost/form and be redirected to http://somehost/response.  You 
> would then want to do a GET on http://somehost/response.
> 
> In either case it is also possible to handle the redirect manually by 
> checking the response code and getting the location header.
> 
> Mike
> 
> Santos wrote:
> 
>> Hi all,
>>
>> I writing to ask you if there's any chance to setFollowRedirects(true)
>> to an instance of PostMethod. I've read in the source that "Entity
>> enclosing requests cannot be redirected without user intervention", but
>> I really need a way to get around this limitation. I know that this is
>> probably due to the HTTP POST spec itself, but I need to invoke an HTTP
>> POST that performs redirection.
>>
>> Thank you,
>> <§@nTº$ />
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


Re: [HttpClient] setFollowRedirects(true) on PostMethod

Posted by Michael Becke <be...@u.washington.edu>.
Hi Santos,

There's no way to make PostMethod automatically redirect, other than 
subclassing and overriding setFollowRedirects().

I question if this is what you want though.  Generally a redirect on 
post indicates that the post succeeded and that the response is to be 
read from the redirected page.  So you would perform a POST to 
http://somehost/form and be redirected to http://somehost/response.  You 
would then want to do a GET on http://somehost/response.

In either case it is also possible to handle the redirect manually by 
checking the response code and getting the location header.

Mike

Santos wrote:

> Hi all,
> 
> I writing to ask you if there's any chance to setFollowRedirects(true)
> to an instance of PostMethod. I've read in the source that "Entity
> enclosing requests cannot be redirected without user intervention", but
> I really need a way to get around this limitation. I know that this is
> probably due to the HTTP POST spec itself, but I need to invoke an HTTP
> POST that performs redirection.
> 
> Thank you,
> <§@nTº$ />
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>