java - URI removes / from path
问题描述
Good morning everyone. I have the following code:
String url = "https://example/example/rest/verify/";
<!-- It is absolutely necessary that code starts with / -->
String code = "/gRmaik5E5rUAoJFy7iovg==";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url).path(code);
UriComponents components = builder.build(true);
URI uri = components.toUri();
ResponseEntity<String> response = new RestTemplate(requestFactory1).exchange(uri, HttpMethod.GET, null, String.class);
The problem is that the uri variable is assigned to the RestTemplate constructor as https://example/example/rest/verify/gRmaik5E5rUAoJFy7iovg==
, that is, it removes the initial /
from the code variable.
I would need the url to look like this: https://example/example/rest/verify//gRmaik5E5rUAoJFy7iovg==
with two //
in the variable code.
Any requests?
解决方案
您可以使用它org.apache.http.client.utils.URIBuilder
来构建 URI。
这会按照您想要的方式构建 URI:
URIBuilder uriBuilder = new URIBuilder(url);
URI uri = uriBuilder.setPath(uriBuilder.getPath() + code).build();
推荐阅读
- android - 在 Android 上找不到 SQLite
- javascript - 从已经包含动画的文件中渲染和动画 SVG
- ios - 滚动时将功能分配给 UIScrollView (Swift)
- hibernate - 线程“HikariPool-3 连接更紧密”中的异常
- python - 如何在 Python 中深度复制 xml 子元素
- image - SSRS 图像过滤器
- sql - 使用左连接排序时的 SQL Server 性能
- python - 如何从列表中字典中的值进行的新计算中创建统计计算,python 3
- sql - sqlplus 添加列标题
- javascript - JavaScript:结合功能、脚本和按钮