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 José Vilson de Mello de Farias <vi...@gmail.com> on 2004/11/07 22:48:26 UTC

problem downloading a zip file

Greetings,

  first I must say that HpptClient is amazing. I was writting http
code by hand and damn it's so hard. Thanks for this great work you're
doing.

  I need some help with file download. I'm trying to download a file,
but the server is redirecting the link a for some reason HttpClient is
not following this new address automatcly.

  Let me show why I'm convinced that my problem is related with redirections :

1 -  I found some comments in log files : 

DEBUG header:71 - << "Date: Sun, 07 Nov 2004 21:31:55 GMT[\r][\n]"
DEBUG header:71 - << "Server: Apache/1.3.31 (Unix)
mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.3.9
FrontPage/5.0.2.2634a mod_ssl/2.8.19 OpenSSL/0.9.7a[\r][\n]"
DEBUG header:71 - << "X-Powered-By: PHP/4.3.9[\r][\n]"
DEBUG header:71 - << "Expires: Thu, 19 Nov 1981 08:52:00 GMT[\r][\n]"
DEBUG header:71 - << "Cache-Control: no-store, no-cache,
must-revalidate, post-check=0, pre-check=0[\r][\n]"
DEBUG header:71 - << "Pragma: no-cache[\r][\n]"
DEBUG header:71 - << "Location:
_legendas/terminator_3_erondisantos_734We840Qk.rar[\r][\n]"
DEBUG header:71 - << "Transfer-Encoding: chunked[\r][\n]"
DEBUG header:71 - << "Content-Type: text/html[\r][\n]"
  ...
  DEBUG HttpMethodBase:943 - Redirect required
   INFO HttpMethodBase:1112 - Redirect requested but followRedirects is disabled
  ...

2 - I checked source code and redirections is alway set to false :
    /**
     * Entity enclosing requests cannot be redirected without user intervention 
     * according to RFC 2616.
     *
     * @param followRedirects must always be <code>false</code>
     */
    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);
    }

Why is it always set to false? How can I get around with this problem?
In the header I can see the real address. I'll try to process it in
order to get follow that link but I think it's not the best option.

Thanks in advance.

Best regards from Brazil.

Vilson

-- 
José Vilson de Mello de Farias 
Analista de Sistemas - APC

DÍGITRO TECNOLOGIA
E-mail: vilson.farias@digitro.com.br / vilson.farias@gmail.com
Fone: (0xx48) 281-7158 / 9121-2432
Fax: (0xx48) 281-7000
Site: www.digitro.com.br / vilsonfarias.trix.net

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


Re: problem downloading a zip file

Posted by José Vilson de Mello de Farias <vi...@gmail.com>.
Thanks a lot for this quick answer. I haven't seen that redirections
guide (my fault). Now I figure out why redirections aren't automatic.

Best regards,

Vilson


On Sun, 07 Nov 2004 23:58:03 +0100, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> 
> José,
> This is exactly what you should be doing. Refer to the HttpClient
> redirect guide for details:
> 
> http://jakarta.apache.org/commons/httpclient/3.0/redirects.html
> 
> Cheers,
> 
> Oleg
> 
> On Sun, 2004-11-07 at 23:13, José Vilson de Mello de Farias wrote:
> > I did a workaround. I'm testing the ReponseHeader, if I find a
> > Location header, then I follow this link with a simple Get method.
> >
> > public final InputStream postUrlAsStream(String relativeURL,
> > NameValuePair[] data) throws HttpException, IOException{
> >     log.debug("getUrlAsBufferedReader()...");
> >     HttpMethod method = executePost(relativeURL, data);
> >
> >     //check if there is redirection...
> >     String location = method.getResponseHeader("Location").getValue();
> >     if (!"".equals(location)){
> >       log.warn("redirection found:" + location);
> >
> >       //follow redirection
> >       log.debug("returning from redirection");
> >       return this.getUrlAsStream("/" + location);
> >     }
> >
> >     InputStream b = method.getResponseBodyAsStream();
> >     log.debug("returning");
> >     return b;
> >   }
> >
> >
> >
> > On Sun, 7 Nov 2004 18:48:26 -0300, José Vilson de Mello de Farias
> > <vi...@gmail.com> wrote:
> > > Greetings,
> > >
> > >   first I must say that HpptClient is amazing. I was writting http
> > > code by hand and damn it's so hard. Thanks for this great work you're
> > > doing.
> > >
> > >   I need some help with file download. I'm trying to download a file,
> > > but the server is redirecting the link a for some reason HttpClient is
> > > not following this new address automatcly.
> > >
> > >   Let me show why I'm convinced that my problem is related with redirections :
> > >
> > > 1 -  I found some comments in log files :
> > >
> > > DEBUG header:71 - << "Date: Sun, 07 Nov 2004 21:31:55 GMT[\r][\n]"
> > > DEBUG header:71 - << "Server: Apache/1.3.31 (Unix)
> > > mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.3.9
> > > FrontPage/5.0.2.2634a mod_ssl/2.8.19 OpenSSL/0.9.7a[\r][\n]"
> > > DEBUG header:71 - << "X-Powered-By: PHP/4.3.9[\r][\n]"
> > > DEBUG header:71 - << "Expires: Thu, 19 Nov 1981 08:52:00 GMT[\r][\n]"
> > > DEBUG header:71 - << "Cache-Control: no-store, no-cache,
> > > must-revalidate, post-check=0, pre-check=0[\r][\n]"
> > > DEBUG header:71 - << "Pragma: no-cache[\r][\n]"
> > > DEBUG header:71 - << "Location:
> > > _legendas/terminator_3_erondisantos_734We840Qk.rar[\r][\n]"
> > > DEBUG header:71 - << "Transfer-Encoding: chunked[\r][\n]"
> > > DEBUG header:71 - << "Content-Type: text/html[\r][\n]"
> > >   ...
> > >   DEBUG HttpMethodBase:943 - Redirect required
> > >    INFO HttpMethodBase:1112 - Redirect requested but followRedirects is disabled
> > >   ...
> > >
> > > 2 - I checked source code and redirections is alway set to false :
> > >     /**
> > >      * Entity enclosing requests cannot be redirected without user intervention
> > >      * according to RFC 2616.
> > >      *
> > >      * @param followRedirects must always be <code>false</code>
> > >      */
> > >     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);
> > >     }
> > >
> > > Why is it always set to false? How can I get around with this problem?
> > > In the header I can see the real address. I'll try to process it in
> > > order to get follow that link but I think it's not the best option.
> > >
> > > Thanks in advance.
> > >
> > > Best regards from Brazil.
> > >
> > > Vilson
> > >
> > > --
> > > José Vilson de Mello de Farias
> > > Analista de Sistemas - APC
> > >
> > > DÍGITRO TECNOLOGIA
> > > E-mail: vilson.farias@digitro.com.br / vilson.farias@gmail.com
> > > Fone: (0xx48) 281-7158 / 9121-2432
> > > Fax: (0xx48) 281-7000
> > > Site: www.digitro.com.br / vilsonfarias.trix.net
> > >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 
> 


-- 
José Vilson de Mello de Farias 
Analista de Sistemas - APC

DÍGITRO TECNOLOGIA
E-mail: vilson.farias@digitro.com.br / vilson.farias@gmail.com
Fone: (0xx48) 281-7158 / 9121-2432
Fax: (0xx48) 281-7000
Site: www.digitro.com.br / vilsonfarias.trix.net

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


Re: problem downloading a zip file

Posted by Oleg Kalnichevski <ol...@apache.org>.
José,
This is exactly what you should be doing. Refer to the HttpClient
redirect guide for details:

http://jakarta.apache.org/commons/httpclient/3.0/redirects.html

Cheers,

Oleg


On Sun, 2004-11-07 at 23:13, José Vilson de Mello de Farias wrote:
> I did a workaround. I'm testing the ReponseHeader, if I find a
> Location header, then I follow this link with a simple Get method.
> 
> public final InputStream postUrlAsStream(String relativeURL,
> NameValuePair[] data) throws HttpException, IOException{
>     log.debug("getUrlAsBufferedReader()...");
>     HttpMethod method = executePost(relativeURL, data);
>         
>     //check if there is redirection...
>     String location = method.getResponseHeader("Location").getValue();
>     if (!"".equals(location)){
>       log.warn("redirection found:" + location);
>       
>       //follow redirection
>       log.debug("returning from redirection");
>       return this.getUrlAsStream("/" + location);
>     }   
>     
>     InputStream b = method.getResponseBodyAsStream();
>     log.debug("returning");
>     return b;
>   }
> 
> 
> 
> On Sun, 7 Nov 2004 18:48:26 -0300, José Vilson de Mello de Farias
> <vi...@gmail.com> wrote:
> > Greetings,
> > 
> >   first I must say that HpptClient is amazing. I was writting http
> > code by hand and damn it's so hard. Thanks for this great work you're
> > doing.
> > 
> >   I need some help with file download. I'm trying to download a file,
> > but the server is redirecting the link a for some reason HttpClient is
> > not following this new address automatcly.
> > 
> >   Let me show why I'm convinced that my problem is related with redirections :
> > 
> > 1 -  I found some comments in log files :
> > 
> > DEBUG header:71 - << "Date: Sun, 07 Nov 2004 21:31:55 GMT[\r][\n]"
> > DEBUG header:71 - << "Server: Apache/1.3.31 (Unix)
> > mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.3.9
> > FrontPage/5.0.2.2634a mod_ssl/2.8.19 OpenSSL/0.9.7a[\r][\n]"
> > DEBUG header:71 - << "X-Powered-By: PHP/4.3.9[\r][\n]"
> > DEBUG header:71 - << "Expires: Thu, 19 Nov 1981 08:52:00 GMT[\r][\n]"
> > DEBUG header:71 - << "Cache-Control: no-store, no-cache,
> > must-revalidate, post-check=0, pre-check=0[\r][\n]"
> > DEBUG header:71 - << "Pragma: no-cache[\r][\n]"
> > DEBUG header:71 - << "Location:
> > _legendas/terminator_3_erondisantos_734We840Qk.rar[\r][\n]"
> > DEBUG header:71 - << "Transfer-Encoding: chunked[\r][\n]"
> > DEBUG header:71 - << "Content-Type: text/html[\r][\n]"
> >   ...
> >   DEBUG HttpMethodBase:943 - Redirect required
> >    INFO HttpMethodBase:1112 - Redirect requested but followRedirects is disabled
> >   ...
> > 
> > 2 - I checked source code and redirections is alway set to false :
> >     /**
> >      * Entity enclosing requests cannot be redirected without user intervention
> >      * according to RFC 2616.
> >      *
> >      * @param followRedirects must always be <code>false</code>
> >      */
> >     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);
> >     }
> > 
> > Why is it always set to false? How can I get around with this problem?
> > In the header I can see the real address. I'll try to process it in
> > order to get follow that link but I think it's not the best option.
> > 
> > Thanks in advance.
> > 
> > Best regards from Brazil.
> > 
> > Vilson
> > 
> > --
> > José Vilson de Mello de Farias
> > Analista de Sistemas - APC
> > 
> > DÍGITRO TECNOLOGIA
> > E-mail: vilson.farias@digitro.com.br / vilson.farias@gmail.com
> > Fone: (0xx48) 281-7158 / 9121-2432
> > Fax: (0xx48) 281-7000
> > Site: www.digitro.com.br / vilsonfarias.trix.net
> > 
> 


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


Re: problem downloading a zip file

Posted by José Vilson de Mello de Farias <vi...@gmail.com>.
I did a workaround. I'm testing the ReponseHeader, if I find a
Location header, then I follow this link with a simple Get method.

public final InputStream postUrlAsStream(String relativeURL,
NameValuePair[] data) throws HttpException, IOException{
    log.debug("getUrlAsBufferedReader()...");
    HttpMethod method = executePost(relativeURL, data);
        
    //check if there is redirection...
    String location = method.getResponseHeader("Location").getValue();
    if (!"".equals(location)){
      log.warn("redirection found:" + location);
      
      //follow redirection
      log.debug("returning from redirection");
      return this.getUrlAsStream("/" + location);
    }   
    
    InputStream b = method.getResponseBodyAsStream();
    log.debug("returning");
    return b;
  }



On Sun, 7 Nov 2004 18:48:26 -0300, José Vilson de Mello de Farias
<vi...@gmail.com> wrote:
> Greetings,
> 
>   first I must say that HpptClient is amazing. I was writting http
> code by hand and damn it's so hard. Thanks for this great work you're
> doing.
> 
>   I need some help with file download. I'm trying to download a file,
> but the server is redirecting the link a for some reason HttpClient is
> not following this new address automatcly.
> 
>   Let me show why I'm convinced that my problem is related with redirections :
> 
> 1 -  I found some comments in log files :
> 
> DEBUG header:71 - << "Date: Sun, 07 Nov 2004 21:31:55 GMT[\r][\n]"
> DEBUG header:71 - << "Server: Apache/1.3.31 (Unix)
> mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.3.9
> FrontPage/5.0.2.2634a mod_ssl/2.8.19 OpenSSL/0.9.7a[\r][\n]"
> DEBUG header:71 - << "X-Powered-By: PHP/4.3.9[\r][\n]"
> DEBUG header:71 - << "Expires: Thu, 19 Nov 1981 08:52:00 GMT[\r][\n]"
> DEBUG header:71 - << "Cache-Control: no-store, no-cache,
> must-revalidate, post-check=0, pre-check=0[\r][\n]"
> DEBUG header:71 - << "Pragma: no-cache[\r][\n]"
> DEBUG header:71 - << "Location:
> _legendas/terminator_3_erondisantos_734We840Qk.rar[\r][\n]"
> DEBUG header:71 - << "Transfer-Encoding: chunked[\r][\n]"
> DEBUG header:71 - << "Content-Type: text/html[\r][\n]"
>   ...
>   DEBUG HttpMethodBase:943 - Redirect required
>    INFO HttpMethodBase:1112 - Redirect requested but followRedirects is disabled
>   ...
> 
> 2 - I checked source code and redirections is alway set to false :
>     /**
>      * Entity enclosing requests cannot be redirected without user intervention
>      * according to RFC 2616.
>      *
>      * @param followRedirects must always be <code>false</code>
>      */
>     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);
>     }
> 
> Why is it always set to false? How can I get around with this problem?
> In the header I can see the real address. I'll try to process it in
> order to get follow that link but I think it's not the best option.
> 
> Thanks in advance.
> 
> Best regards from Brazil.
> 
> Vilson
> 
> --
> José Vilson de Mello de Farias
> Analista de Sistemas - APC
> 
> DÍGITRO TECNOLOGIA
> E-mail: vilson.farias@digitro.com.br / vilson.farias@gmail.com
> Fone: (0xx48) 281-7158 / 9121-2432
> Fax: (0xx48) 281-7000
> Site: www.digitro.com.br / vilsonfarias.trix.net
> 


-- 
José Vilson de Mello de Farias 
Analista de Sistemas - APC

DÍGITRO TECNOLOGIA
E-mail: vilson.farias@digitro.com.br / vilson.farias@gmail.com
Fone: (0xx48) 281-7158 / 9121-2432
Fax: (0xx48) 281-7000
Site: www.digitro.com.br / vilsonfarias.trix.net

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