Last active
August 29, 2015 14:01
-
-
Save fiskurgit/9c21a55cb015065222b8 to your computer and use it in GitHub Desktop.
Fixed Google Volley encodeParameters method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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