接口 WebClient.Builder
- 封闭接口:
- WebClient
public static interface WebClient.Builder
A mutable builder for creating aWebClient.
方法概要
所有方法 实例方法 抽象方法 已过时的方法 修饰符和类型 方法 说明 WebClient.Builderapply(Consumer<WebClient.Builder> builderConsumer)Apply the givenConsumerto this builder instance.WebClient.BuilderbaseUrl(String baseUrl)Configure a base URL for requests.WebClientbuild()Builder theWebClientinstance.WebClient.BuilderclientConnector(ClientHttpConnector connector)Configure theClientHttpConnectorto use.WebClient.Builderclone()Clone thisWebClient.Builder.WebClient.Buildercodecs(Consumer<ClientCodecConfigurer> configurer)WebClient.BuilderdefaultCookie(String cookie, String... values)Global option to specify a cookie to be added to every request, if the request does not already contain such a cookie.WebClient.BuilderdefaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)Provides access to everydefaultCookie(String, String...)declared so far with the possibility to add, replace, or remove.WebClient.BuilderdefaultHeader(String header, String... values)Global option to specify a header to be added to every request, if the request does not already contain such a header.WebClient.BuilderdefaultHeaders(Consumer<HttpHeaders> headersConsumer)Provides access to everydefaultHeader(String, String...)declared so far with the possibility to add, replace, or remove.WebClient.BuilderdefaultRequest(Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest)Provide a consumer to modify every request being built just before the call toexchange().WebClient.BuilderdefaultUriVariables(Map<String,?> defaultUriVariables)Configure default URL variable values to use when expanding URI templates with aMap.WebClient.BuilderexchangeFunction(ExchangeFunction exchangeFunction)WebClient.BuilderexchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer)已过时。as of 5.1.13 in favor ofcodecs(Consumer)WebClient.BuilderexchangeStrategies(ExchangeStrategies strategies)Configure theExchangeStrategiesto use.WebClient.Builderfilter(ExchangeFilterFunction filter)Add the given filter to the end of the filter chain.WebClient.Builderfilters(Consumer<List<ExchangeFilterFunction>> filtersConsumer)Manipulate the filters with the given consumer.WebClient.BuilderuriBuilderFactory(UriBuilderFactory uriBuilderFactory)Provide a pre-configuredUriBuilderFactoryinstance.
方法详细资料
baseUrl
WebClient.Builder baseUrl(String baseUrl)
Configure a base URL for requests. Effectively a shortcut for:String baseUrl = "https://abc.go.com/v1"; DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(baseUrl); WebClient client = WebClient.builder().uriBuilderFactory(factory).build();
The
DefaultUriBuilderFactoryis used to prepare the URL for every request with the given base URL, unless the URL request for a given URL is absolute in which case the base URL is ignored.Note: this method is mutually exclusive with
uriBuilderFactory(UriBuilderFactory). If both are used, the baseUrl value provided here will be ignored.
defaultUriVariables
WebClient.Builder defaultUriVariables(Map<String,?> defaultUriVariables)
Configure default URL variable values to use when expanding URI templates with aMap. Effectively a shortcut for:Map<String, ?> defaultVars = ...; DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); factory.setDefaultVariables(defaultVars); WebClient client = WebClient.builder().uriBuilderFactory(factory).build();
Note: this method is mutually exclusive with
uriBuilderFactory(UriBuilderFactory). If both are used, the defaultUriVariables value provided here will be ignored.
uriBuilderFactory
WebClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
Provide a pre-configuredUriBuilderFactoryinstance. This is an alternative to, and effectively overrides the following shortcut properties:- 参数:
uriBuilderFactory- the URI builder factory to use- 另请参阅:
baseUrl(String),defaultUriVariables(Map)
defaultHeader
WebClient.Builder defaultHeader(String header, String... values)
Global option to specify a header to be added to every request, if the request does not already contain such a header.- 参数:
header- the header namevalues- the header values
defaultHeaders
WebClient.Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer)
Provides access to everydefaultHeader(String, String...)declared so far with the possibility to add, replace, or remove.- 参数:
headersConsumer- the consumer
defaultCookie
WebClient.Builder defaultCookie(String cookie, String... values)
Global option to specify a cookie to be added to every request, if the request does not already contain such a cookie.- 参数:
cookie- the cookie namevalues- the cookie values
defaultCookies
WebClient.Builder defaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
Provides access to everydefaultCookie(String, String...)declared so far with the possibility to add, replace, or remove.- 参数:
cookiesConsumer- a function that consumes the cookies map
defaultRequest
WebClient.Builder defaultRequest(Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest)
Provide a consumer to modify every request being built just before the call toexchange().- 参数:
defaultRequest- the consumer to use for modifying requests- 从以下版本开始:
- 5.1
filter
WebClient.Builder filter(ExchangeFilterFunction filter)
Add the given filter to the end of the filter chain.- 参数:
filter- the filter to be added to the chain
filters
WebClient.Builder filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer)
Manipulate the filters with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove filters, change ordering, etc.- 参数:
filtersConsumer- a function that consumes the filter list- 返回:
- this builder
clientConnector
WebClient.Builder clientConnector(ClientHttpConnector connector)
Configure theClientHttpConnectorto use. This is useful for plugging in and/or customizing options of the underlying HTTP client library (e.g. SSL).By default this is set to
ReactorClientHttpConnector.- 参数:
connector- the connector to use
codecs
WebClient.Builder codecs(Consumer<ClientCodecConfigurer> configurer)
- 参数:
configurer- the configurer to apply- 从以下版本开始:
- 5.1.13
exchangeStrategies
WebClient.Builder exchangeStrategies(ExchangeStrategies strategies)
Configure theExchangeStrategiesto use.For most cases, prefer using
codecs(Consumer)which allows customizing the codecs in theExchangeStrategiesrather than replace them. That ensures multiple parties can contribute to codecs configuration.By default this is set to
ExchangeStrategies.withDefaults().- 参数:
strategies- the strategies to use
exchangeStrategies
@Deprecated WebClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer)
已过时。as of 5.1.13 in favor ofcodecs(Consumer)Customize the strategies configured viaexchangeStrategies(ExchangeStrategies). This method is designed for use in scenarios where multiple parties wish to update theExchangeStrategies.
exchangeFunction
WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction)
Provide anExchangeFunctionpre-configured withClientHttpConnectorandExchangeStrategies.This is an alternative to, and effectively overrides
clientConnector(org.springframework.http.client.reactive.ClientHttpConnector), andexchangeStrategies(ExchangeStrategies).- 参数:
exchangeFunction- the exchange function to use
apply
WebClient.Builder apply(Consumer<WebClient.Builder> builderConsumer)
Apply the givenConsumerto this builder instance.This can be useful for applying pre-packaged customizations.
- 参数:
builderConsumer- the consumer to apply
clone
WebClient.Builder clone()
Clone thisWebClient.Builder.