Closed
Description
Arjen Poutsma opened SPR-6969 and commented
Currently, it's not possible to explicitly set the Content-Type header (or any other header for that matter) for outgoing requests in the RestTemplate. It would be nice to introduce a wrapping HttpEntity
type, which allows you to do this, like so:
HttpEntity<String> entity = new HttpEntity<String>(helloWorld, MediaType.TEXT_PLAIN);
URI location = template.postForLocation("http://example.com/", entity);
Additionally, it would be useful to be able to retrieve response headers as part of a GET operation. The HttpEntity can help here as well:
HttpEntity<String> entity = template.getForEntity("http://example.com", String.class);
String body = entity.getBody();
MediaType contentType = entity.getHeaders().getContentType();
Issue Links:
- RestTemplate - access to Request Headers [SPR-5866] #10535 RestTemplate - access to Request Headers ("is depended on by")
- Support for HttpEntity<?> in @MVC [SPR-7018] #11680 Support for HttpEntity<?> in
@MVC
("is depended on by") - Add PATCH HTTP operation to RestTemplate [SPR-14857] #19423 Add PATCH HTTP operation to RestTemplate
Referenced from: commits 63076d0