简体   繁体   English

Play Framework双网址编码

[英]Play Framework double url encoding

given the following controller method where username = bob and emailAddress = bob@bob.com 给出以下控制器方法,其中username = bob和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 the call the url endpoing receives: 有时当我拨打电话时,url endpoing收到:

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

then other times i get: localhost:8080/api/v1/users/bob/reset_password?email_address= bob%2540bob.com 然后其他时间我得到:localhost:8080 / api / v1 / users / bob / reset_password?email_address = bob%2540bob.com

On the second one the @ has been encoded once to %40 then the % was again encoded to %25 so you end up with %2540 在第二个上,@已被编码一次到%40,然后%再次被编码为%25,所以你最终得到%2540

If I do nothing more than wait a minute the problem goes away which makes me think it's some sort of caching problem but I can't seem to figure out what it is. 如果我什么都不做,等待一分钟问题消失,这让我觉得这是一种缓存问题,但我似乎无法弄清楚它是什么。

最终被认为是一个错误,并已在以后的版本中修复

since this does not repeduce all the times i dont know if that will help but did you try to encode the url? 因为这不会一直重复,我不知道这是否会有所帮助,但你是否尝试对网址进行编码? for example : org.apache.commons.httpclient.util.URIUtil.encodeAll(url); 例如:org.apache.commons.httpclient.util.URIUtil.encodeAll(url);

I think what is happening is when you are calling the controller the first time you send the at symbol as an at symbol. 我认为当你第一次将at符号作为at符号发送时调用控制器时会发生什么。

This then gets encoded into the response and the @ is converted to %40. 然后将其编码到响应中,并将@转换为%40。 I'm guessing when you get this back and you resend it through the browser the % in the %40 gets encoded to %25 making it %2540. 我猜你什么时候回来,你通过浏览器重新发送它,%40中的%被编码为%25,使得%2540。

Sorry if the above is confusing, it is difficult to explain. 对不起,如果上述情况令人困惑,很难解释。

Simple answer would be to just do a replace on the emailAddress variable of %40 to @ before passing it into WS class. 简单的答案是在将%40的emailAddress变量替换为@之前将其传递给WS类。 There is also a urlDecode() method in the play framework which may do the trick, I've used play before but I haven't used this method. 在play框架中还有一个urlDecode()方法可以解决这个问题,我之前使用过play但是我还没有使用过这个方法。

I suspect some form of URL rewriting. 我怀疑某种形式的URL重写。 Do you have an Apache Web Server running in front of your server? 您是否在服务器前运行了Apache Web Server? Maybe some RewriteRule is missing the [NE] flag. 也许有些RewriteRule缺少[NE]标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM