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.
|
<T,P extends org.reactivestreams.Publisher<T>> |
body(P publisher,
java.lang.Class<T> elementClass)
A shortcut for
body(BodyInserter) with a
Publisher inserter. |
<T,P extends org.reactivestreams.Publisher<T>> |
body(P publisher,
ParameterizedTypeReference<T> typeReference)
A variant of
body(Publisher, Class) that allows providing
element type information that includes generics via a
ParameterizedTypeReference . |
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(java.lang.Object body)
A shortcut for
body(BodyInserter) with an
Object inserter. |
accept, acceptCharset, attribute, attributes, cookie, cookies, exchange, header, headers, ifModifiedSince, ifNoneMatch, retrieve
WebClient.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<?> body(BodyInserter<?,? super ClientHttpRequest> inserter)
BodyInserters
provides access to built-in implementations of
BodyInserter
.inserter
- the body inserter to use for the request bodyBodyInserters
<T,P extends org.reactivestreams.Publisher<T>> WebClient.RequestHeadersSpec<?> body(P publisher, java.lang.Class<T> elementClass)
body(BodyInserter)
with a
Publisher inserter.
For example:
MonopersonMono = ... ; Mono 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 Publisher
publisher
- the Publisher
to write to the requestelementClass
- the class of elements contained in the publisher<T,P extends org.reactivestreams.Publisher<T>> WebClient.RequestHeadersSpec<?> body(P publisher, ParameterizedTypeReference<T> typeReference)
body(Publisher, Class)
that allows providing
element type information that includes generics via a
ParameterizedTypeReference
.T
- the type of the elements contained in the publisherP
- the type of the Publisher
publisher
- the Publisher
to write to the requesttypeReference
- the type reference of elements contained in the publisherWebClient.RequestHeadersSpec<?> syncBody(java.lang.Object body)
body(BodyInserter)
with an
Object inserter.
For example:
Person person = ... ; Mono<Void> result = client.post() .uri("/persons/{id}", id) .contentType(MediaType.APPLICATION_JSON) .syncBody(person) .retrieve() .bodyToMono(Void.class);
For multipart requests, provide a
MultiValueMap
. 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. The MultiValueMap
can be built
with MultipartBodyBuilder
.
body
- the Object
to write to the request