接口 WebClient.RequestHeadersSpec<S extends WebClient.RequestHeadersSpec<S>>
- 类型参数:
S
- a self reference to the spec type
- 封闭接口:
- WebClient
public static interface WebClient.RequestHeadersSpec<S extends WebClient.RequestHeadersSpec<S>>
Contract for specifying request headers leading up to the exchange.
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 S
accept(MediaType... acceptableMediaTypes)
Set the list of acceptable media types, as specified by theAccept
header.S
acceptCharset(Charset... acceptableCharsets)
Set the list of acceptable charsets, as specified by theAccept-Charset
header.S
attribute(String name, Object value)
Set the attribute with the given name to the given value.S
attributes(Consumer<Map<String,Object>> attributesConsumer)
Provides access to every attribute declared so far with the possibility to add, replace, or remove values.S
cookie(String name, String value)
Add a cookie with the given name and value.S
cookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
Provides access to every cookie declared so far with the possibility to add, replace, or remove values.reactor.core.publisher.Mono<ClientResponse>
exchange()
Perform the HTTP request and return aClientResponse
with the response status and headers.S
header(String headerName, String... headerValues)
Add the given, single header value under the given name.S
headers(Consumer<HttpHeaders> headersConsumer)
Provides access to every header declared so far with the possibility to add, replace, or remove values.S
ifModifiedSince(ZonedDateTime ifModifiedSince)
Set the value of theIf-Modified-Since
header.S
ifNoneMatch(String... ifNoneMatches)
Set the values of theIf-None-Match
header.WebClient.ResponseSpec
retrieve()
Perform the HTTP request and retrieve the response body:
方法详细资料
accept
S accept(MediaType... acceptableMediaTypes)
Set the list of acceptable media types, as specified by theAccept
header.- 参数:
acceptableMediaTypes
- the acceptable media types- 返回:
- this builder
acceptCharset
S acceptCharset(Charset... acceptableCharsets)
Set the list of acceptable charsets, as specified by theAccept-Charset
header.- 参数:
acceptableCharsets
- the acceptable charsets- 返回:
- this builder
cookie
S cookie(String name, String value)
Add a cookie with the given name and value.- 参数:
name
- the cookie namevalue
- the cookie value- 返回:
- this builder
cookies
S cookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
Provides access to every cookie declared so far with the possibility to add, replace, or remove values.- 参数:
cookiesConsumer
- the consumer to provide access to- 返回:
- this builder
ifModifiedSince
S ifModifiedSince(ZonedDateTime ifModifiedSince)
Set the value of theIf-Modified-Since
header.The date should be specified as the number of milliseconds since January 1, 1970 GMT.
- 参数:
ifModifiedSince
- the new value of the header- 返回:
- this builder
ifNoneMatch
S ifNoneMatch(String... ifNoneMatches)
Set the values of theIf-None-Match
header.- 参数:
ifNoneMatches
- the new value of the header- 返回:
- this builder
header
S header(String headerName, String... headerValues)
Add the given, single header value under the given name.- 参数:
headerName
- the header nameheaderValues
- the header value(s)- 返回:
- this builder
headers
S headers(Consumer<HttpHeaders> headersConsumer)
Provides access to every header declared so far with the possibility to add, replace, or remove values.- 参数:
headersConsumer
- the consumer to provide access to- 返回:
- this builder
attribute
S attribute(String name, Object value)
Set the attribute with the given name to the given value.- 参数:
name
- the name of the attribute to addvalue
- the value of the attribute to add- 返回:
- this builder
attributes
S attributes(Consumer<Map<String,Object>> attributesConsumer)
Provides access to every attribute declared so far with the possibility to add, replace, or remove values.- 参数:
attributesConsumer
- the consumer to provide access to- 返回:
- this builder
retrieve
WebClient.ResponseSpec retrieve()
Perform the HTTP request and retrieve the response body:Mono<Person> bodyMono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(Person.class);
This method is a shortcut to using
exchange()
and decoding the response body throughClientResponse
.- 返回:
ResponseSpec
to specify how to decode the body- 另请参阅:
exchange()
exchange
reactor.core.publisher.Mono<ClientResponse> exchange()
Perform the HTTP request and return aClientResponse
with the response status and headers. You can then use methods of the response to consume the body:Mono<Person> mono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .exchange() .flatMap(response -> response.bodyToMono(Person.class)); Flux<Person> flux = client.get() .uri("/persons") .accept(MediaType.APPLICATION_STREAM_JSON) .exchange() .flatMapMany(response -> response.bodyToFlux(Person.class));
NOTE: Unlike
retrieve()
, when usingexchange()
, it is the responsibility of the application to consume any response content regardless of the scenario (success, error, unexpected data, etc). Not doing so can cause a memory leak. SeeClientResponse
for a list of all the available options for consuming the body. Generally prefer usingretrieve()
unless you have a good reason to useexchange()
which does allow to check the response status and headers before deciding how or if to consume the response.- 返回:
- a
Mono
for the response - 另请参阅:
retrieve()