类 RequestEntity<T>
java.lang.Object
cn.taketoday.http.HttpEntity<T>
cn.taketoday.http.RequestEntity<T>
- 类型参数:
T- the body type
Extension of
HttpEntity that also exposes the HTTP method and the
target URL. For use in the RestTemplate to prepare requests with
and in @Controller methods to represent request input.
Example use with the RestTemplate:
MyRequest body = ...
RequestEntity<MyRequest> request = RequestEntity
.post("https://example.com/{foo}", "bar")
.accept(MediaType.APPLICATION_JSON)
.body(body);
ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
Example use in an @Controller:
@RequestMapping("/handle")
public void handle(RequestEntity<String> request) {
HttpMethod method = request.getMethod();
URI url = request.getUrl();
String body = request.getBody();
}
- 从以下版本开始:
- 4.0 2021/11/5 21:46
- 作者:
- Arjen Poutsma, Sebastien Deleuze, Parviz Rozikov, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceDefines a builder that adds a body to the response entity.private static classstatic interfaceDefines a builder that adds headers to the request entity.static classRequestEntity initialized with a URI template and variables instead of aURI. -
字段概要
字段从类继承的字段 cn.taketoday.http.HttpEntity
EMPTY -
构造器概要
构造器构造器说明RequestEntity(HttpMethod method, URI url) Constructor with method and URL but without body nor headers.RequestEntity(cn.taketoday.util.MultiValueMap<String, String> headers, HttpMethod method, URI url) Constructor with method, URL and headers but without body.RequestEntity(T body, HttpMethod method, URI url) Constructor with method, URL and body but without headers.RequestEntity(T body, HttpMethod method, URI url, Type type) Constructor with method, URL, body and type but without headers.RequestEntity(T body, cn.taketoday.util.MultiValueMap<String, String> headers, HttpMethod method, URI url) Constructor with method, URL, headers and body.RequestEntity(T body, cn.taketoday.util.MultiValueMap<String, String> headers, HttpMethod method, URI url, Type type) Constructor with method, URL, headers, body and type. -
方法概要
修饰符和类型方法说明static RequestEntity.HeadersBuilder<?>Create an HTTP DELETE builder with the given string base uri template.static RequestEntity.HeadersBuilder<?>Create an HTTP DELETE builder with the given url.boolean(专用程序包) static <T> Stringformat(HttpMethod httpMethod, String url, T body, HttpHeaders headers) static RequestEntity.HeadersBuilder<?>Create an HTTP GET builder with the given string base uri template.static RequestEntity.HeadersBuilder<?>Create an HTTP GET builder with the given url.Return the HTTP method of the request.getType()Return the type of the request's body.getUrl()Return theURIfor the target HTTP endpoint.inthashCode()static RequestEntity.HeadersBuilder<?>Create an HTTP HEAD builder with the given string base uri template.static RequestEntity.HeadersBuilder<?>Create an HTTP HEAD builder with the given url.static RequestEntity.BodyBuildermethod(HttpMethod method, String uriTemplate, Object... uriVariables) Create a builder with the given HTTP method, URI template, and variables.static RequestEntity.BodyBuildermethod(HttpMethod method, String uriTemplate, Map<String, ?> uriVariables) Create a builder with the given HTTP method, URI template, and variables.static RequestEntity.BodyBuildermethod(HttpMethod method, URI url) Create a builder with the given method and url.static RequestEntity.HeadersBuilder<?>Creates an HTTP OPTIONS builder with the given string base uri template.static RequestEntity.HeadersBuilder<?>Creates an HTTP OPTIONS builder with the given url.static RequestEntity.BodyBuilderCreate an HTTP PATCH builder with the given string base uri template.static RequestEntity.BodyBuilderCreate an HTTP PATCH builder with the given url.static RequestEntity.BodyBuilderCreate an HTTP POST builder with the given string base uri template.static RequestEntity.BodyBuilderCreate an HTTP POST builder with the given url.static RequestEntity.BodyBuilderCreate an HTTP PUT builder with the given string base uri template.static RequestEntity.BodyBuilderCreate an HTTP PUT builder with the given url.toString()从类继承的方法 cn.taketoday.http.HttpEntity
getBody, getHeaders, hasBody
-
字段详细资料
-
method
-
url
-
type
-
-
构造器详细资料
-
RequestEntity
Constructor with method and URL but without body nor headers.- 参数:
method- the methodurl- the URL
-
RequestEntity
Constructor with method, URL and body but without headers.- 参数:
body- the bodymethod- the methodurl- the URL
-
RequestEntity
Constructor with method, URL, body and type but without headers.- 参数:
body- the bodymethod- the methodurl- the URLtype- the type used for generic type resolution
-
RequestEntity
public RequestEntity(cn.taketoday.util.MultiValueMap<String, String> headers, HttpMethod method, URI url) Constructor with method, URL and headers but without body.- 参数:
headers- the headersmethod- the methodurl- the URL
-
RequestEntity
public RequestEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String, String> headers, @Nullable HttpMethod method, URI url) Constructor with method, URL, headers and body.- 参数:
body- the bodyheaders- the headersmethod- the methodurl- the URL
-
RequestEntity
public RequestEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String, String> headers, @Nullable HttpMethod method, @Nullable URI url, @Nullable Type type) Constructor with method, URL, headers, body and type.- 参数:
body- the bodyheaders- the headersmethod- the methodurl- the URLtype- the type used for generic type resolution
-
-
方法详细资料
-
getMethod
Return the HTTP method of the request.- 返回:
- the HTTP method as an
HttpMethodenum value
-
getUrl
Return theURIfor the target HTTP endpoint.Note: This method raises
UnsupportedOperationExceptionif theRequestEntitywas created with a URI template and variables rather than with aURIinstance. This is because a URI cannot be created without further input on how to expand template and encode the URI. In such cases, theURIis prepared by theRestTemplatewith the help of theUriTemplateHandlerit is configured with. -
getType
Return the type of the request's body.- 返回:
- the request's body type, or
nullif not known
-
equals
- 覆盖:
equals在类中HttpEntity<T>
-
hashCode
public int hashCode()- 覆盖:
hashCode在类中HttpEntity<T>
-
toString
- 覆盖:
toString在类中HttpEntity<T>
-
format
static <T> String format(@Nullable HttpMethod httpMethod, String url, @Nullable T body, HttpHeaders headers) -
method
Create a builder with the given method and url.- 参数:
method- the HTTP method (GET, POST, etc)url- the URL- 返回:
- the created builder
-
method
public static RequestEntity.BodyBuilder method(HttpMethod method, String uriTemplate, Object... uriVariables) Create a builder with the given HTTP method, URI template, and variables.- 参数:
method- the HTTP method (GET, POST, etc)uriTemplate- the uri template to useuriVariables- variables to expand the URI template with- 返回:
- the created builder
-
method
public static RequestEntity.BodyBuilder method(HttpMethod method, String uriTemplate, Map<String, ?> uriVariables) Create a builder with the given HTTP method, URI template, and variables.- 参数:
method- the HTTP method (GET, POST, etc)uriTemplate- the uri template to use- 返回:
- the created builder
-
get
Create an HTTP GET builder with the given url.- 参数:
url- the URL- 返回:
- the created builder
-
get
Create an HTTP GET builder with the given string base uri template.- 参数:
uriTemplate- the uri template to useuriVariables- variables to expand the URI template with- 返回:
- the created builder
-
head
Create an HTTP HEAD builder with the given url.- 参数:
url- the URL- 返回:
- the created builder
-
head
Create an HTTP HEAD builder with the given string base uri template.- 参数:
uriTemplate- the uri template to useuriVariables- variables to expand the URI template with- 返回:
- the created builder
-
post
Create an HTTP POST builder with the given url.- 参数:
url- the URL- 返回:
- the created builder
-
post
Create an HTTP POST builder with the given string base uri template.- 参数:
uriTemplate- the uri template to useuriVariables- variables to expand the URI template with- 返回:
- the created builder
-
put
Create an HTTP PUT builder with the given url.- 参数:
url- the URL- 返回:
- the created builder
-
put
Create an HTTP PUT builder with the given string base uri template.- 参数:
uriTemplate- the uri template to useuriVariables- variables to expand the URI template with- 返回:
- the created builder
-
patch
Create an HTTP PATCH builder with the given url.- 参数:
url- the URL- 返回:
- the created builder
-
patch
Create an HTTP PATCH builder with the given string base uri template.- 参数:
uriTemplate- the uri template to useuriVariables- variables to expand the URI template with- 返回:
- the created builder
-
delete
Create an HTTP DELETE builder with the given url.- 参数:
url- the URL- 返回:
- the created builder
-
delete
Create an HTTP DELETE builder with the given string base uri template.- 参数:
uriTemplate- the uri template to useuriVariables- variables to expand the URI template with- 返回:
- the created builder
-
options
Creates an HTTP OPTIONS builder with the given url.- 参数:
url- the URL- 返回:
- the created builder
-
options
Creates an HTTP OPTIONS builder with the given string base uri template.- 参数:
uriTemplate- the uri template to useuriVariables- variables to expand the URI template with- 返回:
- the created builder
- 从以下版本开始:
- 4.0
-