开发者

Parse Query String with HTTPclient to extract nameValuePairs

Is there Apache utility that takes Query Stri开发者_C百科ng and some encoding and return Map of key,value[] url decoded?


If you are using a 4.x version of HttpClient, you will want to use URLEncodedUtils.parse(). It takes a URI (or string + charset) and returns a List of NameValuePairs.


It's deprecated, but you can use HttpUtils.parseQueryString.

It maps parameter names to values. If the parameter appears more than once, the value is an array.

EDIT: The above method is deprecated because it doesn't allow you to specify character encoding.

The HttpClient project at apache has the classes you need to achieve this.

Use URIUtil.decode(String data, String encoding) to decode the query string.

Then ParameterParser.parse(String query, char separator) to get a list of NameValuePairs. You can then put these into a Commons Collections MultiMap, keyed by parameter name. (You could use a regular hash map, but that involves more code to handle multiple values per key.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜