[英]Get and decode a response from RestTemplate spring boot
I am encoding a URL and when I get the response back it is encoded as well. 我正在编码一个URL,当我收到响应时,它也会被编码。 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? 建议?
response object is of ResponseEntity type. 响应对象是ResponseEntity类型。 You should first get body from response then decode it. 您应该首先从响应中获取主体,然后对其进行解码。
String decodedResult = UriUtils.decode(response.getBody(),"UTF-8");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.