Java Reference
In-Depth Information
if (HttpStatus.SC_OK == httpStatus) {
String xmlResponse = get.getResponseBodyAsString();
System.out.println("Xml Response: " +
xmlResponse);
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
//clean up
get.releaseConnection();
}
}
private static void getHtml() {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(RESOURCE_URL);
get.setRequestHeader("Accept", "text/html");
try {
int httpStatus = client.executeMethod(get);
if (HttpStatus.SC_OK == httpStatus) {
String htmlResponse = get.getResponseBodyAsString();
System.out.println("Html Response: " +
htmlResponse);
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
//clean up
get.releaseConnection();
}
}
private static void getImage() {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(RESOURCE_URL);
get.setRequestHeader("Accept", "image/gif");
try {
Search WWH ::




Custom Search