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
-- "Erare humanum est", Seneca
Thorsten Scherler
Tfno: 955 062 627 Email: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]