【发布时间】:2012-12-04 17:21:36
【问题描述】:
我正在尝试使用来自 RestEasy 的 UriBuilder 从字符串 url 创建一个 URI,但我得到了一些意想不到的结果。我正在运行以下代码。
UriBuilder uriBuilder = UriBuilder.fromPath("http://localhost:8190/items?pageNumber={pageNumber}&pageSize={pageSize}");
System.out.println(uriBuilder.build(1, 10));
预期结果:
http://localhost:8190/items?pageNumber=1&pageSize=10
实际结果:
http://localhost:8190/items%3FpageNumber=1&pageSize=10
当使用 UriBuilder.fromUri() 而不是 fromPath() 时,它会在创建 URI 时引发异常
Illegal character in query at index 39: http://localhost:8190/items?pageNumber={pageNumber}&pageSize={pageSize}
第 39 位的字符是 {。
我不想解析完整的字符串来部分地创建 URI。
我查看了 RestEasy 代码,它正在编码“?”使用 org.jboss.resteasy.util.Encode#encode 使用来自 org.jboss.resteasy.util.Encode#pathEncoding 的 pathEncoding 映射创建构建器时的字符。
是我的用法不正确还是实现不正确?
【问题讨论】: