5

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!

2
  • "There's gotta be something like this right?" unfortunately, no. Split and again. Commented Mar 22, 2011 at 18:28
  • Probable duplicate with: stackoverflow.com/questions/1667278/… . There are a couple of very good answers in there. Commented Mar 22, 2011 at 21:18

2 Answers 2

2

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.
Sign up to request clarification or add additional context in comments.

Comments

0

See this question

One answer there:

import org.eclipse.jetty.util.*;

MultiMap<String> params = new MultiMap<String>();
UrlEncoded.decodeTo("foo=bar&bla=blub", params, "UTF-8");

assert params.getString("foo").equals("bar");
assert params.getString("bla").equals("blub");

6 Comments

that question doesn't seem to address my problem. I said I didn't want to do the splits.
basically you're saying, "no".
There are a lot of answers, as for example using the apache libs or the jetty libs, then they will split and encode for you.
uh oh, yeah you're right. there is this one can look into: hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/…
apparently that package doesn't exist?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.