Reputation: 12061
I am encoding a URL and when I get the response back it is encoded as well. What I am having a issue with is decoding it.
String encoded = URLEncoder.encode(text,"UTF-8");
UriComponentsBuilder builder = UriComponentsBuilder
.fromUriString("https://google.com/translate")
.queryParam("srcLang", srcLang)
.queryParam("tgtLang", tgtLang)
.queryParam("text", encoded);
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(),HttpMethod.GET, request, String.class);
what I was trying to do is:
String decodedResult = UriUtils.decode(response.toString(),"UTF-8");
But that didn't work.
advice?
Upvotes: 0
Views: 2045
Reputation: 827
response object is of ResponseEntity type. You should first get body from response then decode it.
String decodedResult = UriUtils.decode(response.getBody(),"UTF-8");
Upvotes: 1