Parse Query String with HTTPclient to retrieve nameValuePairs

Is there an Apache utility that takes a Query String and some encoding and returns Map of key, the value [] url decoded?

+7
java url tomcat apache decoding
source share
2 answers

It is 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 does not allow for character encoding.

The HttpClient project in apache has the classes needed 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 NameValuePair s. You can then put them in the Commons MultiMap collection using the parameter name. (You can use a regular hash map, but this requires more code to process multiple values ​​for each key.)

+7
source

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

+7
source

All Articles