我正在使用rest模板创建HTTP post
请求。但默认情况下,请求包含了包含大量内容的accept char头。请建议如何排除添加该标题。下面是我正在使用的代码:
HttpHeader header= new HttpHeader();
RestTemplate template = new RestTemplate();
header.setContentType("application/xml");
String body=" content of body ";
HttpEntity<string> request=new HttpEntity<string> (body,header);
template.postForObject(URL,request,String.class);
最佳答案
这将删除“accept charset”头:
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
stringHttpMessageConverter.setWriteAcceptCharset(false);
restTemplate.getMessageConverters().add(0, stringHttpMessageConverter);