hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andre John Mas <a...@expedia.com>
Subject Re: Once again 302 :(
Date Mon, 01 Mar 2004 18:15:10 GMT
I am not really in a position to test the code, but could you see 
whether changing the value of the 'user-agent' header gives:

  method.setRequestHeader("user-agent",
      "Mozilla/5.0 (Windows; U; Windows NT 5.0;
       en-US; rv:1.6) Gecko/20040113");

or

  method.setRequestHeader("user-agent",
      "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021");

Values taken from: http://nycbug.org/stat/agent_200312.html

Also what JDK versions are you using?

Andre


Thorsten Scherler wrote:

> Hello group,
> I have a similar problem like Emre.
> 
> ...but this time the problem depends on the plattform I am on. I am a 
> little bit confused because it is running fine on win but on linux not.
> 
> Site causing the problem:
> andaluciajunta.es
> 
> Windows:
> I get 302!
> 
> Linux (debian):
> org.apache.commons.httpclient.HttpConnection$ConnectionTimeoutException
> 
> My code:
> public String getHttp(String address) throws Exception {
>        //        Create an instance of HttpClient.
>        org.apache.commons.httpclient.HttpClient client =
>            new org.apache.commons.httpclient.HttpClient();
>        String url = null;
>        String protocol = "http://";
>        String protocolS = "https://";
>        //System.out.println("address->"+address);
>        if (address.indexOf(protocol) > -1) {
>            url = address;
>        } else if (address.indexOf(protocolS) > -1) {
>            url = address;
>        } else {
>            url = protocol + address;
>        }
>        //        establish a connection within 5 seconds
>        client.setConnectionTimeout(5000);              // Create a 
> method instance.
>        HttpMethod method = new GetMethod(url);
>        method.setFollowRedirects(true);
>        //        Execute the method.
>        int statusCode = -1;
>        int attempt = 0;
>        // We will retry up to 3 times.
>        while (statusCode == -1 && attempt < 3) {
>            attempt += 1;
>            try {
>                // execute the method.
>                statusCode = client.executeMethod(method);
>            } catch (HttpRecoverableException e) {
>                System.err.println(
>                    "A recoverable exception occurred, retrying."
>                        + e.getMessage());
>            } catch (IOException e) {
>                System.err.println("Failed to download file.");
>                e.printStackTrace();
>                return "666";
>            }
>        }
>        // Check that we didn't run out of retries.
>        if (statusCode == -1) {
>            System.err.println("Failed to recover from exception.");
>            return "666";
>        }
> 
>        //Read the response code
>        try {
>            int code = method.getStatusCode();
>            //System.err.println(code);
>            //Release the connection.
>            method.releaseConnection();
>            return String.valueOf(code);
>        } catch (RuntimeException e1) {
>            e1.printStackTrace();
>            //Release the connection.
>            method.releaseConnection();
>            //this is not a valid HTTP code, it was choosen because of 
> that ;-)
>            return "666";
>        }
>    }
> 
> King regards
> 


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


Mime
View raw message