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
[{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());