private HttpUriRequest createRequest(URIBuilder builder, Collection<NameValuePair> params) throws URISyntaxException, UnsupportedEncodingException {
Collection<NameValuePair> p = getApiParams();
params.addAll(p);
if(apiProperties.getUseHttpGet()) {
for (NameValuePair nvp : params){
builder.addParameter(nvp.getName(), nvp.getValue());
}
URI uri = builder.build();
getLogger().trace("CREATING GET: " + URLDecoder.decode(uri.toString(), "UTF-8"));
return new HttpGet(uri);
}
else {
URI uri = builder.build();
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(params, Charset.forName("utf-8"));
StringWriter writer = new StringWriter();
try {
IOUtils.copy(formEntity.getContent(), writer, "utf-8");
} catch (IOException e) {
getLogger().debug("Error when writing POST entity to string: " + e.getMessage(), e);
}
getLogger().trace("CREATING POST: " + URLDecoder.decode(uri.toString(), "UTF-8") + "?" + URLDecoder.decode(writer.toString(), "UTF-8"));
HttpPost post = new HttpPost(uri);
post.setEntity(formEntity);
return post;
}
}