添加一个 Converter
设置 UTF-8 编码
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
// 添加自定义的 ClientHttpRequestInterceptor 全局 JSON 請求
restTemplate.setInterceptors(Collections.singletonList(new CustomClientHttpRequestInterceptor()));
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
restTemplate.getInterceptors().add((request, body, execution) -> {
return execution.execute(request, body);
});
return restTemplate;
}
}
标签:return,webservice,request,restTemplate,乱码,RestTemplate,new
From: https://www.cnblogs.com/liruilong/p/17876960.html