URI从路径中移除/



大家早上好。我有以下代码:

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);
问题是uri变量被分配给RestTemplate构造函数作为https://example/example/rest/verify/gRmaik5E5rUAoJFy7iovg==,也就是说,它从code变量中删除了初始的/

我需要url看起来像这样:https://example/example/rest/verify//gRmaik5E5rUAoJFy7iovg==和两个//在变量代码。

请求吗?

您可以使用org.apache.http.client.utils.URIBuilder来构建URI。
这会按照您想要的方式构建URI:

URIBuilder uriBuilder = new URIBuilder(url);
URI uri = uriBuilder.setPath(uriBuilder.getPath() + code).build();

相关内容

  • 没有找到相关文章

最新更新