0

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?

karel
  • 5,489
  • 46
  • 45
  • 50
David
  • 1

1 Answers1

0

You could use org.apache.http.client.utils.URIBuilder to build the URI.
This builds the URI the way you want it:

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