} else if (!(url.startsWith("http://") || url.startsWith("https://"))) {
url = getBaseURL() + url;
}
HttpEntityEnclosingRequestBase httpMethod = null;
try {
if (method.equals("PUT")) {
httpMethod = new HttpPut(url);
} else if (method.equals("POST")) {
httpMethod = new HttpPost(url);
} else {
throw new IllegalArgumentException("method must be one of PUT or POST.");
}
httpMethod.setHeader(HttpHeaders.CONNECTION, "Keep-Alive");
if (requestContent != null) {
if (requestContent instanceof String) {
StringEntity entity = new StringEntity((String) requestContent,
Charset.forName("UTF-8"));
entity.setChunked(chunked);
httpMethod.setEntity(entity);
} else if (requestContent instanceof File) {
MultipartEntity entity =
new MultipartEntity();
entity.addPart(((File) requestContent)
.getName(), new FileBody((File) requestContent));
entity.addPart("param_name", new StringBody("value"));
httpMethod.setEntity(entity);
} else {
throw new IllegalArgumentException("requestContent must be a String or File");
}
}
return getClient(authenticate).execute(httpMethod);
} finally {
if (httpMethod != null) {
httpMethod.releaseConnection();
}
}
}