![]() |
腹黑的墨镜 · cmd | Microsoft Learn· 6 月前 · |
![]() |
求醉的大熊猫 · 如何重定向到其他屏幕,而无需按下React本 ...· 9 月前 · |
![]() |
怕老婆的海龟 · python ...· 1 年前 · |
![]() |
年轻有为的签字笔 · 是否有可能排除来自java父pom的mave ...· 1 年前 · |
![]() |
越狱的泡面 · DSO学习笔记四 ...· 1 年前 · |
Implemented by
RestTemplate
. Not often used directly, but a useful
option to enhance testability, as it can easily be mocked or stubbed.
RestTemplate
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
String
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
Class
<T> responseType,
Map
<
String
,
?> uriVariables)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
String
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
ParameterizedTypeReference
<T> responseType,
Object
... uriVariables)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
String
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
ParameterizedTypeReference
<T> responseType,
Map
<
String
,
?> uriVariables)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
URI
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
Class
<T> responseType)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
URI
url,
HttpMethod
method,
HttpEntity
<?> requestEntity,
ParameterizedTypeReference
<T> responseType)
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
RequestEntity
<?> requestEntity,
Class
<T> responseType)
RequestEntity
and return
the response as
ResponseEntity
.
<T>
ResponseEntity
<T>
exchange
(
RequestEntity
<?> requestEntity,
ParameterizedTypeReference
<T> responseType)
RequestEntity
and return
the response as
ResponseEntity
.
execute
(
String
uriTemplate,
HttpMethod
method,
RequestCallback
requestCallback,
ResponseExtractor
<T> responseExtractor,
Object
... uriVariables)
RequestCallback
, and reading the response with a
ResponseExtractor
.
execute
(
String
uriTemplate,
HttpMethod
method,
RequestCallback
requestCallback,
ResponseExtractor
<T> responseExtractor,
Map
<
String
,
?> uriVariables)
RequestCallback
, and reading the response with a
ResponseExtractor
.
execute
(
URI
url,
HttpMethod
method,
RequestCallback
requestCallback,
ResponseExtractor
<T> responseExtractor)
RequestCallback
, and reading the response with a
ResponseExtractor
.
<T>
ResponseEntity
<T>
getForEntity
(
String
url,
Class
<T> responseType,
Object
... uriVariables)
<T>
ResponseEntity
<T>
getForEntity
(
String
url,
Class
<T> responseType,
Map
<
String
,
?> uriVariables)
<T>
ResponseEntity
<T>
getForEntity
(
URI
url,
Class
<T> responseType)
getForObject
(
String
url,
Class
<T> responseType,
Object
... uriVariables)
getForObject
(
String
url,
Class
<T> responseType,
Map
<
String
,
?> uriVariables)
getForObject
(
URI
url,
Class
<T> responseType)
headForHeaders
(
String
url,
Object
... uriVariables)
headForHeaders
(
String
url,
Map
<
String
,
?> uriVariables)
headForHeaders
(
URI
url)
Set
<
HttpMethod
>
optionsForAllow
(
String
url,
Object
... uriVariables)
Allow
header for the given URI.
Set
<
HttpMethod
>
optionsForAllow
(
String
url,
Map
<
String
,
?> uriVariables)
Allow
header for the given URI.
Set
<
HttpMethod
>
optionsForAllow
(
URI
url)
Allow
header for the given URL.
patchForObject
(
String
url,
Object
request,
Class
<T> responseType,
Object
... uriVariables)
patchForObject
(
String
url,
Object
request,
Class
<T> responseType,
Map
<
String
,
?> uriVariables)
patchForObject
(
URI
url,
Object
request,
Class
<T> responseType)
<T>
ResponseEntity
<T>
postForEntity
(
String
url,
Object
request,
Class
<T> responseType,
Object
... uriVariables)
ResponseEntity
.
<T>
ResponseEntity
<T>
HttpEntity
.
<T>
ResponseEntity
<T>
postForEntity
(
URI
url,
Object
request,
Class
<T> responseType)
ResponseEntity
.
postForLocation
(
String
url,
Object
request,
Object
... uriVariables)
Location
header.
postForLocation
(
String
url,
Object
request,
Map
<
String
,
?> uriVariables)
Location
header.
postForLocation
(
URI
url,
Object
request)
Location
header.
postForObject
(
String
url,
Object
request,
Class
<T> responseType,
Object
... uriVariables)
postForObject
(
URI
url,
Object
request,
Class
<T> responseType)
URI Template variables are expanded using the given URI variables, if any.
url
- the URL
responseType
- the type of the return value
uriVariables
- the variables to expand the template
RestClientException
URI Template variables are expanded using the given map.
url
- the URL
responseType
- the type of the return value
uriVariables
- the map containing variables for the URI template
RestClientException
url
- the URL
responseType
- the type of the return value
RestClientException
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
url
- the URL
responseType
- the type of the return value
uriVariables
- the variables to expand the template
RestClientException
ResponseEntity
.
URI Template variables are expanded using the given map.
url
- the URL
responseType
- the type of the return value
uriVariables
- the map containing variables for the URI template
RestClientException
ResponseEntity
.
url
- the URL
responseType
- the type of the return value
RestClientException
URI Template variables are expanded using the given URI variables, if any.
url
- the URL
uriVariables
- the variables to expand the template
RestClientException
URI Template variables are expanded using the given map.
url
- the URL
uriVariables
- the map containing variables for the URI template
RestClientException
url
- the URL
RestClientException
Location
header. This header typically indicates where the new resource is stored.
URI Template variables are expanded using the given URI variables, if any.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
The body of the entity, or
request
itself, can be a
MultiValueMap
to create a multipart request.
The values in the
MultiValueMap
can be any Object representing the body of the part,
or an
HttpEntity
representing a part with body
and headers.
url
- the URL
request
- the Object to be POSTed (may be
null
)
uriVariables
- the variables to expand the template
Location
header
RestClientException
HttpEntity
Location
header. This header typically indicates where the new resource is stored.
URI Template variables are expanded using the given map.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request
The body of the entity, or
request
itself, can be a
MultiValueMap
to create a multipart request.
The values in the
MultiValueMap
can be any Object representing the body of the part,
or an
HttpEntity
representing a part with body
and headers.
url
- the URL
request
- the Object to be POSTed (may be
null
)
uriVariables
- the variables to expand the template
Location
header
RestClientException
HttpEntity
Location
header. This header typically indicates where the new resource is stored.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
The body of the entity, or
request
itself, can be a
MultiValueMap
to create a multipart request.
The values in the
MultiValueMap
can be any Object representing the body of the part,
or an
HttpEntity
representing a part with body
and headers.
url
- the URL
request
- the Object to be POSTed (may be
null
)
Location
header
RestClientException
HttpEntity
URI Template variables are expanded using the given URI variables, if any.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
The body of the entity, or
request
itself, can be a
MultiValueMap
to create a multipart request.
The values in the
MultiValueMap
can be any Object representing the body of the part,
or an
HttpEntity
representing a part with body
and headers.
url
- the URL
request
- the Object to be POSTed (may be
null
)
responseType
- the type of the return value
uriVariables
- the variables to expand the template
RestClientException
HttpEntity
URI Template variables are expanded using the given map.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
The body of the entity, or
request
itself, can be a
MultiValueMap
to create a multipart request.
The values in the
MultiValueMap
can be any Object representing the body of the part,
or an
HttpEntity
representing a part with body
and headers.
url
- the URL
request
- the Object to be POSTed (may be
null
)
responseType
- the type of the return value
uriVariables
- the variables to expand the template
RestClientException
HttpEntity
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
The body of the entity, or
request
itself, can be a
MultiValueMap
to create a multipart request.
The values in the
MultiValueMap
can be any Object representing the body of the part,
or an
HttpEntity
representing a part with body
and headers.
url
- the URL
request
- the Object to be POSTed (may be
null
)
responseType
- the type of the return value
RestClientException
HttpEntity
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
The body of the entity, or
request
itself, can be a
MultiValueMap
to create a multipart request.
The values in the
MultiValueMap
can be any Object representing the body of the part,
or an
HttpEntity
representing a part with body
and headers.
url
- the URL
request
- the Object to be POSTed (may be
null
)
uriVariables
- the variables to expand the template
RestClientException
HttpEntity
HttpEntity
.
URI Template variables are expanded using the given map.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
The body of the entity, or
request
itself, can be a
MultiValueMap
to create a multipart request.
The values in the
MultiValueMap
can be any Object representing the body of the part,
or an
HttpEntity
representing a part with body
and headers.
url
- the URL
request
- the Object to be POSTed (may be
null
)
uriVariables
- the variables to expand the template
RestClientException
HttpEntity
ResponseEntity
.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
The body of the entity, or
request
itself, can be a
MultiValueMap
to create a multipart request.
The values in the
MultiValueMap
can be any Object representing the body of the part,
or an
HttpEntity
representing a part with body
and headers.
url
- the URL
request
- the Object to be POSTed (may be
null
)
RestClientException
HttpEntity
URI Template variables are expanded using the given URI variables, if any.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
url
- the URL
request
- the Object to be PUT (may be
null
)
uriVariables
- the variables to expand the template
RestClientException
HttpEntity
URI Template variables are expanded using the given map.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
url
- the URL
request
- the Object to be PUT (may be
null
)
uriVariables
- the variables to expand the template
RestClientException
HttpEntity
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
url
- the URL
request
- the Object to be PUT (may be
null
)
RestClientException
HttpEntity
URI Template variables are expanded using the given URI variables, if any.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
NOTE: The standard JDK HTTP library does not support HTTP PATCH. You need to use the Apache HttpComponents or OkHttp request factory.
url
- the URL
request
- the object to be PATCHed (may be
null
)
responseType
- the type of the return value
uriVariables
- the variables to expand the template
RestClientException
HttpEntity
InterceptingHttpAccessor.setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory)
HttpComponentsClientHttpRequestFactory
OkHttp3ClientHttpRequestFactory
URI Template variables are expanded using the given map.
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
NOTE: The standard JDK HTTP library does not support HTTP PATCH. You need to use the Apache HttpComponents or OkHttp request factory.
url
- the URL
request
- the object to be PATCHed (may be
null
)
responseType
- the type of the return value
uriVariables
- the variables to expand the template
RestClientException
HttpEntity
InterceptingHttpAccessor.setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory)
HttpComponentsClientHttpRequestFactory
OkHttp3ClientHttpRequestFactory
The
request
parameter can be a
HttpEntity
in order to
add additional HTTP headers to the request.
NOTE: The standard JDK HTTP library does not support HTTP PATCH. You need to use the Apache HttpComponents or OkHttp request factory.
url
- the URL
request
- the object to be PATCHed (may be
null
)
responseType
- the type of the return value
RestClientException
HttpEntity
InterceptingHttpAccessor.setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory)
HttpComponentsClientHttpRequestFactory
OkHttp3ClientHttpRequestFactory
URI Template variables are expanded using the given URI variables, if any.
url
- the URL
uriVariables
- the variables to expand in the template
RestClientException
URI Template variables are expanded using the given map.
url
- the URL
uriVariables
- the variables to expand the template
RestClientException
url
- the URL
RestClientException
Allow
header for the given URI.
URI Template variables are expanded using the given URI variables, if any.
url
- the URL
uriVariables
- the variables to expand in the template
Allow
header
RestClientException
Allow
header for the given URI.
URI Template variables are expanded using the given map.
url
- the URL
uriVariables
- the variables to expand in the template
Allow
header
RestClientException
Allow
header for the given URL.
url
- the URL
Allow
header
RestClientException
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
url
- the URL
method
- the HTTP method (GET, POST, etc)
requestEntity
- the entity (headers and/or body) to write to the request
may be
null
)
responseType
- the type to convert the response to, or
Void.class
for no body
uriVariables
- the variables to expand in the template
RestClientException
ResponseEntity
.
URI Template variables are expanded using the given URI variables, if any.
url
- the URL
method
- the HTTP method (GET, POST, etc)
requestEntity
- the entity (headers and/or body) to write to the request
(may be
null
)
responseType
- the type to convert the response to, or
Void.class
for no body
uriVariables
- the variables to expand in the template
RestClientException
ResponseEntity
.
url
- the URL
method
- the HTTP method (GET, POST, etc)
requestEntity
- the entity (headers and/or body) to write to the request
(may be
null
)
responseType
- the type to convert the response to, or
Void.class
for no body
RestClientException
ResponseEntity
.
The given
ParameterizedTypeReference
is used to pass generic type information:
ParameterizedTypeReference<List<MyBean>> myBean =
new ParameterizedTypeReference<List<MyBean>>() {};
ResponseEntity<List<MyBean>> response =
template.exchange("https://example.com",HttpMethod.GET, null, myBean);
url
- the URL
method
- the HTTP method (GET, POST, etc)
requestEntity
- the entity (headers and/or body) to write to the
request (may be
null
)
responseType
- the type to convert the response to, or
Void.class
for no body
uriVariables
- the variables to expand in the template
RestClientException
ResponseEntity
.
The given
ParameterizedTypeReference
is used to pass generic type information:
ParameterizedTypeReference<List<MyBean>> myBean =
new ParameterizedTypeReference<List<MyBean>>() {};
ResponseEntity<List<MyBean>> response =
template.exchange("https://example.com",HttpMethod.GET, null, myBean);
url
- the URL
method
- the HTTP method (GET, POST, etc)
requestEntity
- the entity (headers and/or body) to write to the request
(may be
null
)
responseType
- the type to convert the response to, or
Void.class
for no body
uriVariables
- the variables to expand in the template
RestClientException
ResponseEntity
.
The given
ParameterizedTypeReference
is used to pass generic type information:
ParameterizedTypeReference<List<MyBean>> myBean =
new ParameterizedTypeReference<List<MyBean>>() {};
ResponseEntity<List<MyBean>> response =
template.exchange("https://example.com",HttpMethod.GET, null, myBean);
url
- the URL
method
- the HTTP method (GET, POST, etc)
requestEntity
- the entity (headers and/or body) to write to the request
(may be
null
)
responseType
- the type to convert the response to, or
Void.class
for no body
RestClientException
RequestEntity
and return
the response as
ResponseEntity
. Typically used in combination
with the static builder methods on
RequestEntity
, for instance:
MyRequest body = ...
RequestEntity request = RequestEntity
.post(URI.create("https://example.com/foo"))
.accept(MediaType.APPLICATION_JSON)
.body(body);
ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
requestEntity
- the entity to write to the request
responseType
- the type to convert the response to, or
Void.class
for no body
RestClientException
RequestEntity
and return
the response as
ResponseEntity
. The given
ParameterizedTypeReference
is used to pass generic type information:
MyRequest body = ...
RequestEntity request = RequestEntity
.post(URI.create("https://example.com/foo"))
.accept(MediaType.APPLICATION_JSON)
.body(body);
ParameterizedTypeReference<List<MyResponse>> myBean =
new ParameterizedTypeReference<List<MyResponse>>() {};
ResponseEntity<List<MyResponse>> response = template.exchange(request, myBean);
requestEntity
- the entity to write to the request
responseType
- the type to convert the response to, or
Void.class
for no body
RestClientException
RequestCallback
, and reading the response with a
ResponseExtractor
.
URI Template variables are expanded using the given URI variables, if any.
uriTemplate
- the URI template
method
- the HTTP method (GET, POST, etc)
requestCallback
- object that prepares the request
responseExtractor
- object that extracts the return value from the response
uriVariables
- the variables to expand in the template
ResponseExtractor
RestClientException
RequestCallback
, and reading the response with a
ResponseExtractor
.
URI Template variables are expanded using the given URI variables map.
uriTemplate
- the URI template
method
- the HTTP method (GET, POST, etc)
requestCallback
- object that prepares the request
responseExtractor
- object that extracts the return value from the response
uriVariables
- the variables to expand in the template
ResponseExtractor
RestClientException
RequestCallback
, and reading the response with a
ResponseExtractor
.
url
- the URL
method
- the HTTP method (GET, POST, etc)
requestCallback
- object that prepares the request
responseExtractor
- object that extracts the return value from the response
ResponseExtractor
RestClientException
![]() |
腹黑的墨镜 · cmd | Microsoft Learn 6 月前 |