接口 WebClient.RequestHeadersSpec<S extends WebClient.RequestHeadersSpec<S>>
- 类型参数:
S- a self reference to the spec type
- 所有已知子接口:
WebClient.RequestBodySpec,WebClient.RequestBodyUriSpec,WebClient.RequestHeadersUriSpec<S>
- 封闭接口:
- WebClient
-
方法概要
修饰符和类型方法说明Set the list of acceptable media types, as specified by theAcceptheader.acceptCharset(Charset... acceptableCharsets) Set the list of acceptable charsets, as specified by theAccept-Charsetheader.Set the attribute with the given name to the given value.attributes(Consumer<Map<String, Object>> attributesConsumer) Provides access to every attribute declared so far with the possibility to add, replace, or remove values.Provide a function to populate the ReactorContext.Add a cookie with the given name and value.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 aClientResponsewith the response status and headers.<V> reactor.core.publisher.Flux<V>exchangeToFlux(Function<ClientResponse, ? extends reactor.core.publisher.Flux<V>> responseHandler) An alternative toretrieve()that provides more control via access to theClientResponse.<V> reactor.core.publisher.Mono<V>exchangeToMono(Function<ClientResponse, ? extends reactor.core.publisher.Mono<V>> responseHandler) An alternative toretrieve()that provides more control via access to theClientResponse.Add the given, single header value under the given name.headers(Consumer<HttpHeaders> headersConsumer) Provides access to every header declared so far with the possibility to add, replace, or remove values.httpRequest(Consumer<ClientHttpRequest> requestConsumer) Callback for access to theClientHttpRequestthat in turn provides access to the native request of the underlying HTTP library.ifModifiedSince(ZonedDateTime ifModifiedSince) Set the value of theIf-Modified-Sinceheader.ifNoneMatch(String... ifNoneMatches) Set the values of theIf-None-Matchheader.retrieve()Proceed to declare how to extract the response.
-
方法详细资料
-
accept
Set the list of acceptable media types, as specified by theAcceptheader.- 参数:
acceptableMediaTypes- the acceptable media types- 返回:
- this builder
-
acceptCharset
Set the list of acceptable charsets, as specified by theAccept-Charsetheader.- 参数:
acceptableCharsets- the acceptable charsets- 返回:
- this builder
-
cookie
Add a cookie with the given name and value.- 参数:
name- the cookie namevalue- the cookie value- 返回:
- this builder
-
cookies
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
Set the value of theIf-Modified-Sinceheader.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
Set the values of theIf-None-Matchheader.- 参数:
ifNoneMatches- the new value of the header- 返回:
- this builder
-
header
Add the given, single header value under the given name.- 参数:
headerName- the header nameheaderValues- the header value(s)- 返回:
- this builder
-
headers
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
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
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
-
context
Provide a function to populate the ReactorContext.- 参数:
contextModifier- the function to modify the context with
-
httpRequest
Callback for access to theClientHttpRequestthat in turn provides access to the native request of the underlying HTTP library. This could be useful for setting advanced, per-request options that exposed by the underlying library.- 参数:
requestConsumer- a consumer to access theClientHttpRequestwith- 返回:
ResponseSpecto specify how to decode the body
-
retrieve
WebClient.ResponseSpec retrieve()Proceed to declare how to extract the response. For example to extract aResponseEntitywith status, headers, and body:Mono<ResponseEntity<Person>> entityMono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .retrieve() .toEntity(Person.class);Or if interested only in the body:
Mono<Person> entityMono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(Person.class);By default, 4xx and 5xx responses result in a
WebClientResponseException. To customize error handling, useonStatushandlers. -
exchangeToMono
<V> reactor.core.publisher.Mono<V> exchangeToMono(Function<ClientResponse, ? extends reactor.core.publisher.Mono<V>> responseHandler) An alternative toretrieve()that provides more control via access to theClientResponse. This can be useful for advanced scenarios, for example to decode the response differently depending on the response status:Mono<Person> entityMono = client.get() .uri("/persons/1") .accept(MediaType.APPLICATION_JSON) .exchangeToMono(response -> { if (response.statusCode().equals(HttpStatus.OK)) { return response.bodyToMono(Person.class); } else { return response.createError(); } });Note: After the returned
Monocompletes, the response body is automatically released if it hasn't been consumed. If the response content is needed, the provided function must declare how to decode it.- 类型参数:
V- the type of Object the response will be transformed to- 参数:
responseHandler- the function to handle the response with- 返回:
- a
Monoproduced from the response
-
exchangeToFlux
<V> reactor.core.publisher.Flux<V> exchangeToFlux(Function<ClientResponse, ? extends reactor.core.publisher.Flux<V>> responseHandler) An alternative toretrieve()that provides more control via access to theClientResponse. This can be useful for advanced scenarios, for example to decode the response differently depending on the response status:Flux<Person> entityMono = client.get() .uri("/persons") .accept(MediaType.APPLICATION_JSON) .exchangeToFlux(response -> { if (response.statusCode().equals(HttpStatus.OK)) { return response.bodyToFlux(Person.class); } else { return response.createError().flux(); } });Note: After the returned
Fluxcompletes, the response body is automatically released if it hasn't been consumed. If the response content is needed, the provided function must declare how to decode it.- 类型参数:
V- the type of Objects the response will be transformed to- 参数:
responseHandler- the function to handle the response with- 返回:
- a
Fluxof Objects produced from the response
-
exchange
reactor.core.publisher.Mono<ClientResponse> exchange()Perform the HTTP request and return aClientResponsewith 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. SeeClientResponsefor 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.Possibility to leak memory and/or connections; please use
exchangeToMono(Function),exchangeToFlux(Function); consider also usingretrieve()which provides access to the response status and headers viaResponseEntityalong with error status handling.- 返回:
- a
Monofor the response - 另请参阅:
-