public static interface WebClient.RequestBodySpec extends WebClient.RequestHeadersSpec<WebClient.RequestBodySpec>
| Modifier and Type | Method and Description |
|---|---|
WebClient.RequestHeadersSpec<?> |
body(BodyInserter<?,? super ClientHttpRequest> inserter)
Set the body of the request using the given body inserter.
|
WebClient.RequestHeadersSpec<?> |
body(Object producer,
Class<?> elementClass)
Variant of
body(Publisher, Class) that allows using any
producer that can be resolved to Publisher via
ReactiveAdapterRegistry. |
WebClient.RequestHeadersSpec<?> |
body(Object producer,
ParameterizedTypeReference<?> elementTypeRef)
Variant of
body(Publisher, ParameterizedTypeReference) that
allows using any producer that can be resolved to Publisher
via ReactiveAdapterRegistry. |
<T,P extends Publisher<T>> |
body(P publisher,
Class<T> elementClass)
Shortcut for
body(BodyInserter) with a
Publisher inserter. |
<T,P extends Publisher<T>> |
body(P publisher,
ParameterizedTypeReference<T> elementTypeRef)
Variant of
body(Publisher, Class) that allows providing
element type information with generics. |
WebClient.RequestHeadersSpec<?> |
bodyValue(Object body)
Shortcut for
body(BodyInserter) with a
value inserter. |
WebClient.RequestBodySpec |
contentLength(long contentLength)
Set the length of the body in bytes, as specified by the
Content-Length header. |
WebClient.RequestBodySpec |
contentType(MediaType contentType)
Set the media type of the body, as specified
by the
Content-Type header. |
WebClient.RequestHeadersSpec<?> |
syncBody(Object body)
Deprecated.
as of Spring Framework 5.2 in favor of
bodyValue(Object) |
accept, acceptCharset, attribute, attributes, context, cookie, cookies, exchange, exchangeToFlux, exchangeToMono, header, headers, httpRequest, ifModifiedSince, ifNoneMatch, retrieveWebClient.RequestBodySpec contentLength(long contentLength)
Content-Length header.contentLength - the content lengthHttpHeaders.setContentLength(long)WebClient.RequestBodySpec contentType(MediaType contentType)
Content-Type header.contentType - the content typeHttpHeaders.setContentType(MediaType)WebClient.RequestHeadersSpec<?> bodyValue(Object body)
body(BodyInserter) with a
value inserter.
For example:
Person person = ... ;
Mono<Void> result = client.post()
.uri("/persons/{id}", id)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(person)
.retrieve()
.bodyToMono(Void.class);
For multipart requests consider providing
MultiValueMap prepared
with MultipartBodyBuilder.
body - the value to write to the request bodyIllegalArgumentException - if body is a
Publisher or producer known to ReactiveAdapterRegistry<T,P extends Publisher<T>> WebClient.RequestHeadersSpec<?> body(P publisher, Class<T> elementClass)
body(BodyInserter) with a
Publisher inserter.
For example:
Mono<Person> personMono = ... ;
Mono<Void> result = client.post()
.uri("/persons/{id}", id)
.contentType(MediaType.APPLICATION_JSON)
.body(personMono, Person.class)
.retrieve()
.bodyToMono(Void.class);
T - the type of the elements contained in the publisherP - the type of the Publisherpublisher - the Publisher to write to the requestelementClass - the type of elements published<T,P extends Publisher<T>> WebClient.RequestHeadersSpec<?> body(P publisher, ParameterizedTypeReference<T> elementTypeRef)
body(Publisher, Class) that allows providing
element type information with generics.T - the type of the elements contained in the publisherP - the type of the Publisherpublisher - the Publisher to write to the requestelementTypeRef - the type of elements publishedWebClient.RequestHeadersSpec<?> body(Object producer, Class<?> elementClass)
body(Publisher, Class) that allows using any
producer that can be resolved to Publisher via
ReactiveAdapterRegistry.producer - the producer to write to the requestelementClass - the type of elements producedWebClient.RequestHeadersSpec<?> body(Object producer, ParameterizedTypeReference<?> elementTypeRef)
body(Publisher, ParameterizedTypeReference) that
allows using any producer that can be resolved to Publisher
via ReactiveAdapterRegistry.producer - the producer to write to the requestelementTypeRef - the type of elements producedWebClient.RequestHeadersSpec<?> body(BodyInserter<?,? super ClientHttpRequest> inserter)
BodyInserters for built-in BodyInserter implementations.inserter - the body inserter to use for the request bodyBodyInserters@Deprecated WebClient.RequestHeadersSpec<?> syncBody(Object body)
bodyValue(Object)body(BodyInserter) with a
value inserter.
As of 5.2 this method delegates to bodyValue(Object).