firen
firen

Reputation: 1424

How to get url parameters values from HTTPRequest in Apache HTTPClient

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?

Upvotes: 0

Views: 5873

Answers (2)

Dennie
Dennie

Reputation: 912

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.

Upvotes: 0

Liviu Munteanu
Liviu Munteanu

Reputation: 26

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.

Upvotes: 1

Related Questions