这是 UriBuilder 的预期行为吗?
这就是我正在做的事情(JAX-RS 1.0,Jersey 1.11):
import javax.ws.rs.core.UriBuilder;
System.out.println(UriBuilder.fromPath("/").queryParam("x", "%40").build());
System.out.println(UriBuilder.fromPath("/").queryParam("x", "100%").build());
预期:
/?x=%2540
/?x=100%25
但实际输出是:
/?x=%40
/?x=100%25
发生了什么?如果这是 UriBuilder
的行为方式,那么解决方法是什么?
This is what I'm doing (JAX-RS 1.0, Jersey 1.11):
import javax.ws.rs.core.UriBuilder;
System.out.println(UriBuilder.fromPath("/").queryParam("x", "%40").build());
System.out.println(UriBuilder.fromPath("/").queryParam("x", "100%").build());
Expected:
/?x=%2540
/?x=100%25
But actual output is:
/?x=%40
/?x=100%25
What is going on? What is a workaround if this is how UriBuilder
should behave?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我很惊讶,但这就是它的工作原理:
I'm surprised, but this is how it works:
问题可能是有一种额外的方法可以从编码字符串构建 URI:
来自 Javadocs:
build(): “字符串化值中的所有 '%' 字符都将被编码。构建器的状态不受影响”
buildFromEncoded(): “字符串化值中的所有 % 字符 将被编码后面不跟两个十六进制数字的将被编码。”
URIBuilder.buildFromEncoded()
:http://jsr311.java.net/nonav/javadoc/javax/ws/rs/core/UriBuilder.html#buildFromEncoded%28java.lang.Object...%29?
希望有帮助
The problem might be that there is an extra method for building URIs from encoded Strings:
From the Javadocs:
build(): "All '%' characters in the stringified values will be encoded. The state of the builder is unaffected"
buildFromEncoded(): "All % characters in the stringified values that are not followed by two hexadecimal numbers will be encoded."
URIBuilder.buildFromEncoded()
:http://jsr311.java.net/nonav/javadoc/javax/ws/rs/core/UriBuilder.html#buildFromEncoded%28java.lang.Object...%29?
hope that helped