// Returns params string only, e.g. // application_id=774&auth_key=aY7WwSRmu2-GbfA&nonce=1451135156 private String getEncodedParamsOnlyString(boolean encoded) { StringBuilder paramsOnly = new StringBuilder(); if (parameters.size() > 0) { for (String key : parameters.keySet()) { String value = parameters.get(key); if (value != null) { String encodedValue = encoded ? URLEncoder.encode(value) : value; paramsOnly.append(String.format("%s=%s&", key, encodedValue)); } } // remove last '&' paramsOnly.deleteCharAt(paramsOnly.length() - 1); } return paramsOnly.toString(); }
public HttpEntity getBody() { HttpEntity entity = null; if (body == null) { if ((method == RestMethod.POST || method == RestMethod.PUT) && parameters.size() > 0) { List<NameValuePair> bodyParams = new ArrayList<NameValuePair>(); for (String key : parameters.keySet()) { bodyParams.add(new BasicNameValuePair(key, parameters.get(key))); } try { entity = new UrlEncodedFormEntity(bodyParams, ConstsGlobal.DEFAULT_ENCODING); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } } } else { entity = body; } return entity; }