Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fixed Google Volley encodeParameters method
* Converts <code>params</code> into an application/x-www-form-urlencoded encoded string.
private byte[] encodeParameters(Map<String, String> params, String paramsEncoding) {
StringBuilder encodedParams = new StringBuilder();
try {
for(Iterator<Map.Entry<String, String>> i = params.entrySet().iterator(); i.hasNext(); ){
Map.Entry<String, String> entry =;
encodedParams.append(URLEncoder.encode(entry.getKey(), paramsEncoding));
encodedParams.append(URLEncoder.encode(entry.getValue(), paramsEncoding));
return encodedParams.toString().getBytes(paramsEncoding);
} catch (UnsupportedEncodingException uee) {
throw new RuntimeException("Encoding not supported: " + paramsEncoding, uee);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment