This is most likely not a problem. I assume that you did not specify the correct message converter. But here is the header removal technique so you can confirm that:
1. Create a custom implementation of ClientHttpRequestInterceptor :
public class CustomHttpRequestInterceptor implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { HttpHeaders headers = request.getHeaders(); headers.remove(HttpHeaders.CONNECTION); headers.remove(HttpHeaders.CONTENT_TYPE); headers.remove(HttpHeaders.CONTENT_LENGTH); return execution.execute(request, body); } }
2. Then add it to the RestTemplate chain of interceptors:
@Bean public RestTemplate restTemplate() { RestTemplate restTemplate = new RestTemplate(); restTemplate.setInterceptors(Arrays.asList(new CustomHttpRequestInterceptor(), new LoggingRequestInterceptor())); return restTemplate; }
source share