Skip to content

Introduce HttpEntity [SPR-6969] #11634

Closed
Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 63076d0

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions