hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: Getting 200 code when 301 is executed
Date Fri, 07 Jan 2005 13:38:14 GMT
Greg,

It is also possible to disable redirects and then handle them manually.  
  Setting the HttpClient param "http.protocol.max-redirects" to 0 will  
do this.  See  
<http://jakarta.apache.org/commons/httpclient/3.0/preference- 
api.html#HTTP%20client%20parameters>.

Mike

On Jan 7, 2005, at 4:14 AM, Ortwin Glück wrote:

> Hi Greg,
>
> The redirect is completely handled inside HttpClient. You get the  
> response code of the last request, which is 2xx normally. The only way  
> to know if the request was redirected, is to compare the URI of the  
> request after execution with the one before execution:
>
> HttpMethod get = new GetMethod("....");
> URI uri = get.getURI();
> client.execute(get);
> boolean wasRedirected = ! method.getURI().equals(uri);
>
> Ortwin Glück
>
> Gregory Gershman wrote:
>> I'm upgrading from version 2.X to 3.X, looking to get rid of some of  
>> my
>> redirect code.  I've noticed that when I hit a URL that returns a 301,
>> the new 3.1 client automatically redirects to the new Location, and
>> fetches it successfully.  This is good, but the status code returned  
>> is
>> a 200, not a 301; I have no way of finding out if I should permanently
>> change the URL in my database.  Is there access to the earlier request
>> responses?  I would think that in the case of a 301, the response code
>> should not be 200...
>>  Greg Gershman
>
> -- 
>  _________________________________________________________________
>  NOSE applied intelligence ag
>
>  ortwin glück                      [www]      http://www.nose.ch
>  software engineer
>  hardturmstrasse 171               [pgp id]           0x81CF3416
>  8005 zürich                       [office]      +41-1-277 57 35
>  switzerland                       [fax]         +41-1-277 57 12
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
>


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


Mime
View raw message