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 Janos Mucsi <ja...@macys.com> on 2008/05/13 00:53:58 UTC

detecting redirects with GetMethod

1. If I follow redirects

 HttpClient client = new HttpClient();
 GetMethod method = new GetMethod("http://....";
 method.setFollowRedirects(true);
 client.executeMethod(method);
System.out.println(method.getURI());
method.releaseConnection();

Yes, then I can compare the first and the second URLs.

2. If I do not follow the redirect


HttpClient client = new HttpClient();

 GetMethod method = new GetMethod("http://....";
 method.setFollowRedirects(false);
 client.executeMethod(method);
Header header = method.getResponseHeader("Location");

// when header!=null
System.out.println(header.getValue());
method.releaseConnection();


Which solution do you think is nicer or less resource intensive? I need 
to do about 17,000 validations so I care about speed too.

Thanks.


sebb wrote:
> method.getURI()
>
> On 12/05/2008, Janos Mucsi <ja...@macys.com> wrote:
>   
>> Hi
>>
>>  I am following redirects like this
>>
>>  HttpClient client = new HttpClient();
>>  GetMethod method = new GetMethod("http://....";
>>  method.setFollowRedirects(true);
>>  client.executeMethod(method);
>>
>>  I would like to compare the new URL to the old URL in case of redirects.
>> What is the most efficient way
>>  to do this if I do not want to make two separate connections?
>>     
>
> Have you tried calling
>
> method.getURI()
>
> after the executeMethod() has returned?
>
>   
>>  In my case this is necessary because the company I am working for uses
>> redirects just to change cookies,
>>  so I need to distinguish between real redirects (when the URL is different)
>> and fake redirects (when cookies
>>  are different only).
>>
>>  Thanks.
>>
>>  --
>>  Janos Mucsi
>>
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
>
>   


-- 
Janos Mucsi
415-222-1411


Re: detecting redirects with GetMethod

Posted by sebb <se...@gmail.com>.
On 12/05/2008, Janos Mucsi <ja...@macys.com> wrote:
> 1. If I follow redirects
>
>  HttpClient client = new HttpClient();
>  GetMethod method = new GetMethod("http://....";
>  method.setFollowRedirects(true);
>  client.executeMethod(method);
>  System.out.println(method.getURI());
>  method.releaseConnection();
>
>  Yes, then I can compare the first and the second URLs.
>
>  2. If I do not follow the redirect
>
>
>  HttpClient client = new HttpClient();
>
>  GetMethod method = new GetMethod("http://....";
>  method.setFollowRedirects(false);
>  client.executeMethod(method);
>  Header header = method.getResponseHeader("Location");
>
>  // when header!=null
>  System.out.println(header.getValue());
>  method.releaseConnection();
>

The above code samples are not equivalent, as the second one does not
fetch the redirected URL.

>
>  Which solution do you think is nicer or less resource intensive? I need to
> do about 17,000 validations so I care about speed too.

Then I suggest you try some tests to measure speed and resource usage.

>  Thanks.
>
>
>  sebb wrote:
>
> > method.getURI()
> >
> > On 12/05/2008, Janos Mucsi <ja...@macys.com> wrote:
> >
> >
> > > Hi
> > >
> > >  I am following redirects like this
> > >
> > >  HttpClient client = new HttpClient();
> > >  GetMethod method = new GetMethod("http://....";
> > >  method.setFollowRedirects(true);
> > >  client.executeMethod(method);
> > >
> > >  I would like to compare the new URL to the old URL in case of
> redirects.
> > > What is the most efficient way
> > >  to do this if I do not want to make two separate connections?
> > >
> > >
> >
> > Have you tried calling
> >
> > method.getURI()
> >
> > after the executeMethod() has returned?
> >
> >
> >
> > >  In my case this is necessary because the company I am working for uses
> > > redirects just to change cookies,
> > >  so I need to distinguish between real redirects (when the URL is
> different)
> > > and fake redirects (when cookies
> > >  are different only).
> > >
> > >  Thanks.
> > >
> > >  --
> > >  Janos Mucsi
> > >
> > >
> > >
> > >
> > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail:
> httpclient-users-help@hc.apache.org
> >
> >
> >
> >
> >
>
>
>  --
>  Janos Mucsi
>  415-222-1411
>
>

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