Created
January 20, 2014 05:26
-
-
Save yanhua365/8515289 to your computer and use it in GitHub Desktop.
用Java解析HTTP Request的params参数,生成一个Map的代码。http://stackoverflow.com/questions/13592236/parse-the-uri-string-into-name-value-collection-in-java
This file contains hidden or 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
public static Map<String, String> splitQuery(URL url) throws UnsupportedEncodingException { | |
Map<String, String> query_pairs = new LinkedHashMap<String, String>(); | |
String query = url.getQuery(); | |
String[] pairs = query.split("&"); | |
for (String pair : pairs) { | |
int idx = pair.indexOf("="); | |
query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); | |
} | |
return query_pairs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment