SpringBoot RestTemplate一般请求返回值是JSON,如果是XML会报错.
下面是处理方式
//返回值是XML,修改返回值为XML
RestTemplate restTemplate = new RestTemplate();
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_XML, MediaType.APPLICATION_PROBLEM_XML));
restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);
ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(url, null, String.class);
网友评论