Play Framework Dual URL Encoding

the following controller method is specified, where username = bob and emailAddress = bob@bob.com

public static void resetPassword(String username, String emailAddress) { String url = BASE_URL + "/users/" + username + "/reset_password"; HttpResponse response = WS.url(url).setParameter("email_address", emailAddress).get(); } 

Sometimes, when I make a call, the resulting URL gets:

local: 8080 / api / v1 / users / bob / reset_password email_address = bob% 40bob.com

then in other cases I get: local: 8080 / API / v1 / users / bob / reset_password email_address = bob% 2540bob.com

In the second case, @ was encoded once to% 40, and then% was again encoded to% 25, ​​so you ended up in% 2540

If I do no more than wait a minute, the problem disappears, which makes me think of some kind of caching problem, but I can’t understand what it is.

+6
java urlencode playframework
source share
4 answers

was finally recognized as a bug and was fixed in a later release

+4
source share

since it doesn't repeat all the time when I don't know if this will help, but have you tried to encode the url? for example: org.apache.commons.httpclient.util.URIUtil.encodeAll (URL);

0
source share

I think what happens when you call the controller the first time you send a character as a character.

Then it gets the encoding in response, and @ is converted to% 40. I assume that when you get it back and you send it again through the browser,% in% 40 gets the encoding up to% 25, ​​making it% 2540.

Sorry, if the above is confusing, it's hard to explain.

A simple answer would be to simply replace the replacement with the emailAddress variable from% 40 to @ before passing it to the WS class. There is also a urlDecode () method in the playback structure that can do the trick, I used the game before, but I did not use this method.

0
source share

I suspect you are rewriting the url. Do you have an Apache web server running in front of your server? Perhaps in some RewriteRule the [NE] flag is missing.

0
source share

All Articles