I am trying to access the contents of an API and I need to send a URL using RestTemplate.
String url1 = \"http://api.example.com/Search?key=52ddafbe3ee659bad
If the solution suggested by sotirios-delimanolis is a little difficult to implement in a scenario, and if the URI string containing curly braces and other characters is guaranteed to be correct, it might be simpler to pass the encoded URI string to a method of RestTemplate
that hits the ReST
server.
The URI string can be built using UriComponentsBuilder.build(), encoded using UriComponents.encode(), and sent using RestTemplate.exchange() like this:
public ResponseEntity
Building, encoding, and extracting URI have been seperated out for clarity in the above code snippet.