java.lang.Object | |
↳ | org.springframework.http.HttpEntity<T> |
Known Direct Subclasses |
Represents an HTTP request or response entity, consisting of headers and body.
Typically used in combination with the RestTemplate
, like so:
HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); HttpEntity<String> entity = new HttpEntity<String>(helloWorld, headers); URI location = template.postForLocation("http://example.com", entity);or
HttpEntity<String> entity = template.getForEntity("http://example.com", String.class); String body = entity.getBody(); MediaType contentType = entity.getHeaders().getContentType();Can also be used in Spring MVC, as a return value from a @Controller method:
@RequestMapping("/handle") public HttpEntity<String> handle() { HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.set("MyResponseHeader", "MyValue"); return new HttpEntity<String>("Hello World", responseHeaders); }
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
EMPTY | The empty HttpEntity , with no body or headers. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new
HttpEntity with the given body and no headers. | |||||||||||
Create a new
HttpEntity with the given headers and no body. | |||||||||||
Create a new
HttpEntity with the given body and headers. |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new, empty
HttpEntity . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the body of this entity.
| |||||||||||
Returns the headers of this entity.
| |||||||||||
Indicates whether this entity has a body.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Create a new HttpEntity
with the given body and no headers.
body | the entity body |
---|
Create a new HttpEntity
with the given headers and no body.
headers | the entity headers |
---|
Create a new HttpEntity
with the given body and headers.
body | the entity body |
---|---|
headers | the entity headers |
Create a new, empty HttpEntity
.
Returns the body of this entity.
Indicates whether this entity has a body.