In Spring RestTemplate is there a way to send Custom Headers together with a POST Request Object. I have already tried out the exchange
method which is available. It seems that we can send key value pairs together with a custom headers but not a request object itself attached to the HttpEntity.
The following code illustrates the attempt and it seems to be 400 BadRequest
for the server.
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<?> httpEntity = new HttpEntity<Object>(requestDTO, requestHeaders);
RestTemplate restTemplate = new RestTemplate();
restTemplate.exchange(URL, HttpMethod.POST, httpEntity, SomeObject.class);
Anyone aware about this situation ? Or is it something which is not possible that Im trying to do ?