Skip to content

Instantly share code, notes, and snippets.

Embed
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 = i.next();
encodedParams.append(URLEncoder.encode(entry.getKey(), paramsEncoding));
encodedParams.append('=');
encodedParams.append(URLEncoder.encode(entry.getValue(), paramsEncoding));
if(i.hasNext()){
encodedParams.append('&');
}
}
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