Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

URLEncodedUtils.parse returns the URL itself as first entry. What im doing wrong?

I try to get the query params of an redirectUri. So I tried out the URLEncodedUtils helper.

List<NameValuePair> parse = URLEncodedUtils.parse(redirectedTo, Charset.defaultCharset());

It works fine, but as result of.

https://my.redirect.de/foo?code=123&state=123

I got a List

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[{name:https://my.redirect.de/foo?code, value: 123}, {name:state, value:123}]

This is suboptimal. What im doing wrong? When I first have to split the params from the URL the helperclass isnt helpful that much. Any suggestions are welcome

>Solution :

In the documentation it is stated Returns a list of NameValuePairs as parsed from the given string using the given character encoding. By convention, ‘&’ and ‘;’ are accepted as parameter separators.

So the questionmark is not a separator, hence no distinction is made as to the URL part.

I don’t know in what context you are using this, but generally in Java there are methods to retrieve the querystring, which you can then pass to your method.

What I would do:

URL url = new URL("https://my.redirect.de/foo?code=123&state=123");
String queryString = url.getQuery();
List<NameValuePair> parse = URLEncodedUtils.parse(queryString, Charset.defaultCharset());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading