byte[] byteArray = null;
HttpMethod method = null;
try {
HttpClient client =
new HttpClient(new SimpleHttpConnectionManager());
if (location == null) {
return byteArray;
}
else if (!location.startsWith(HTTP_WITH_SLASH) &&
!location.startsWith(HTTPS_WITH_SLASH)) {
location = HTTP_WITH_SLASH + location;
}
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost(new URI(location));
if (Validator.isNotNull(PROXY_HOST) && PROXY_PORT > 0) {
hostConfig.setProxy(PROXY_HOST, PROXY_PORT);
}
client.setHostConfiguration(hostConfig);
client.setConnectionTimeout(5000);
client.setTimeout(5000);
if (cookies != null && cookies.length > 0) {
HttpState state = new HttpState();
state.addCookies(cookies);
state.setCookiePolicy(CookiePolicy.COMPATIBILITY);
client.setState(state);
}
if (post) {
method = new PostMethod(location);
}
else {
method = new GetMethod(location);
}
method.setFollowRedirects(true);
client.executeMethod(method);
Header locationHeader = method.getResponseHeader("location");
if (locationHeader != null) {
return URLtoByteArray(locationHeader.getValue(), cookies, post);
}