if (creds != null) {
client.getState().setCredentials(AuthScope.ANY, creds);
}
String url = args[0];
HttpMethod method = null;
//create a method object
method = new GetMethod(url);
method.setFollowRedirects(true);
//} catch (MalformedURLException murle) {
// System.out.println("<url> argument '" + url
// + "' is not a valid URL");
// System.exit(-2);
//}
//execute the method
String responseBody = null;
try{
client.executeMethod(method);
responseBody = method.getResponseBodyAsString();
} catch (HttpException he) {
System.err.println("Http error connecting to '" + url + "'");
System.err.println(he.getMessage());
System.exit(-4);
} catch (IOException ioe){
System.err.println("Unable to connect to '" + url + "'");
System.exit(-3);
}
//write out the request headers
System.out.println("*** Request ***");
System.out.println("Request Path: " + method.getPath());
System.out.println("Request Query: " + method.getQueryString());
Header[] requestHeaders = method.getRequestHeaders();
for (int i=0; i<requestHeaders.length; i++){
System.out.print(requestHeaders[i]);
}
//write out the response headers
System.out.println("*** Response ***");
System.out.println("Status Line: " + method.getStatusLine());
Header[] responseHeaders = method.getResponseHeaders();
for (int i=0; i<responseHeaders.length; i++){
System.out.print(responseHeaders[i]);
}
//write out the response body
System.out.println("*** Response Body ***");
System.out.println(responseBody);
//clean up the connection resources
method.releaseConnection();
System.exit(0);
}