0

I would like to take value of specific parameter in query string. Is there any method in HttpClient which can do if for me (ex. util class method) or I have to write my own?

2 Answers 2

1

In 4.X.X there is:

    List<NameValuePair> parameters = URLEncodedUtils.parse(new URI(
                request.getRequestLine().getUri()), HTTP.UTF_8);

        for (NameValuePair nameValuePair : parameters) {
            System.out.println(nameValuePair.getName() + ": "
                    + nameValuePair.getValue());
        }

Then handle your own parameter.

Sign up to request clarification or add additional context in comments.

1 Comment

There's no such method signature for URLEncodedUtils.parse, and HTTP.UTF_8 is deprecated. Try URLEncodedUtils.parse(new URI(request.getRequestLine().getUri()).getQuery(), StandardCharsets.UTF_8);.
1

In Apache Http Client 5.x.x URLEncodedUtils is deprecated. You can use:

      final List<NameValuePair> pairs = new URIBuilder(request.getUri()).getQueryParams();

This uses UTF8 decoding by default.

Comments

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.