Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get parameters out of a url encoded string (not a URL) in java

Tags:

java

I have a url encoded string that is returned from an API I am using. I want to do something request.getParameter("paramname") on the string. What I'm looking for is something like str.request.getParameter("paramname"). There's gotta be something like this right?

clarification the api returns something like: name1=val1&name2=val2&name3=val3

I know i could do a split on "&" and then go through each element but that seems stupid. Please advise. Thanks!

like image 208
Lye Avatar asked Nov 06 '22 00:11

Lye


1 Answers

Use URLEncodedUtils from Apache httpclient library.

API : http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/utils/URLEncodedUtils.html

You will have to call this method to get name value pairs:

static List<NameValuePair>  parse(HttpEntity entity)
          Returns a list of NameValuePairs as parsed from an HttpEntity.
like image 136
Shamit Verma Avatar answered Nov 12 '22 14:11

Shamit Verma