类 HttpEntity<T>
java.lang.Object
cn.taketoday.http.HttpEntity<T>
- 类型参数:
T- the body type
Represents an HTTP request or response entity, consisting of headers and body.
like so:
HttpHeaders headers = HttpHeaders.create();
headers.setContentType(MediaType.TEXT_PLAIN);
HttpEntity<String> entity = new HttpEntity<>(helloWorld, headers);
URI location = template.postForLocation("https://example.com", entity);
or
HttpEntity<String> entity = template.getForEntity("https://example.com", String.class);
String body = entity.getBody();
MediaType contentType = entity.getHeaders().getContentType();
Can also be used in Web MVC, as a return value from a @Controller method:
@RequestMapping("/handle")
public HttpEntity<String> handle() {
HttpHeaders responseHeaders = HttpHeaders.create();
responseHeaders.set("MyResponseHeader", "MyValue");
return new HttpEntity<>("Hello World", responseHeaders);
}
- 从以下版本开始:
- 3.0 2020/12/6 17:10
- 作者:
- Arjen Poutsma, Juergen Hoeller, Harry Yang
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private final Tstatic final HttpEntity<?>The emptyHttpEntity, with no body or headers.private final HttpHeaders -
构造器概要
构造器限定符构造器说明protectedCreate a new, emptyHttpEntity.HttpEntity(cn.taketoday.util.MultiValueMap<String, String> headers) Create a newHttpEntitywith the given headers and no body.HttpEntity(T body) Create a newHttpEntitywith the given body and no headers.HttpEntity(T body, cn.taketoday.util.MultiValueMap<String, String> headers) Create a newHttpEntitywith the given body and headers. -
方法概要
-
字段详细资料
-
EMPTY
The emptyHttpEntity, with no body or headers. -
headers
-
body
-
-
构造器详细资料
-
HttpEntity
protected HttpEntity()Create a new, emptyHttpEntity. -
HttpEntity
Create a newHttpEntitywith the given body and no headers.- 参数:
body- the entity body
-
HttpEntity
Create a newHttpEntitywith the given headers and no body.- 参数:
headers- the entity headers
-
HttpEntity
public HttpEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String, String> headers) Create a newHttpEntitywith the given body and headers.- 参数:
body- the entity bodyheaders- the entity headers
-
-
方法详细资料