To prevent `RestTemplate` from URL encoding of URL value which has already been encoded, use `UriComponentsBuilder` as follows:
uri = UriComponentsBuilder.fromHttpUrl(url).build(true).toUri();
echoed = restTemplate.getForObject(uri, String.class);
assertThat(echoed).isEqualTo(message);
Note the invocation on `build()` with `encoded` parameter having `true` value.
You can see the full sample code in: https://github.com/izeye/spring-boot-throwaway-branches/blob/rest/src/test/java/learningtest/org/springframework/web/client/RestTemplateTests.java
Reference:
http://stackoverflow.com/questions/28182836/resttemplate-to-not-escape-url
No comments:
Post a Comment