Interface RequestSpec.Body
-
- Enclosing interface:
- RequestSpec
public static interface RequestSpec.Body
The request body.The methods of this type are not additive. That is, successive calls to
bytes(byte[])
and other methods will not add to the request body. Rather, they will replace the content specified by previous method calls.It is generally best to provide the body content in the format that you have it in. That is, if you already have the desired body content as a
String
, use thetext(CharSequence)
method. If you already have the desired body content as abyte[]
, use thebytes(byte[])
method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description RequestSpec.Body
buffer(io.netty.buffer.ByteBuf byteBuf)
Specifies the request body as a byte buffer.RequestSpec.Body
bytes(byte[] bytes)
Specifies the request body as a byte array.RequestSpec.Body
stream(Publisher<? extends io.netty.buffer.ByteBuf> publisher, long contentLength)
Specifies that the request body will be supplied by the given publisher, with the given content length.RequestSpec.Body
stream(Action<? super OutputStream> action)
Specifies the request body by writing to an output stream.RequestSpec.Body
streamUnknownLength(Publisher<? extends io.netty.buffer.ByteBuf> publisher)
Specifies that the request body will be supplied by the given publisher, with an unknown length.RequestSpec.Body
text(CharSequence text)
Specifies the request body as a UTF-8 char sequence.RequestSpec.Body
text(CharSequence text, Charset charset)
Specifies the request body as a char sequence of the given charset.RequestSpec.Body
type(CharSequence contentType)
Specifies the"Content-Type"
of the request.
-
-
-
Method Detail
-
type
RequestSpec.Body type(CharSequence contentType)
Specifies the"Content-Type"
of the request.Call this method has the same effect as using
RequestSpec.getHeaders()
orRequestSpec.headers(Action)
to set the"Content-Type"
header.- Parameters:
contentType
- the value of the Content-Type header- Returns:
- this
-
stream
RequestSpec.Body stream(Action<? super OutputStream> action) throws Exception
Specifies the request body by writing to an output stream.The output stream is not directly connected to the HTTP server. That is, bytes written to the given output stream are not directly streamed to the server. There is no performance advantage in using this method over methods such as
bytes(byte[])
.- Parameters:
action
- an action that writes to the request body to the- Returns:
- this
- Throws:
Exception
- any thrown by action
-
stream
RequestSpec.Body stream(Publisher<? extends io.netty.buffer.ByteBuf> publisher, long contentLength)
Specifies that the request body will be supplied by the given publisher, with the given content length.A maximum length of
contentLength
will be sent. Any surplus bytes emitted by the publisher will be discarded. If the publisher emits fewer bytes thancontentLength
, the connection will be closed and an exception propagated.The publisher may be subscribed to multiple times, if the request is redirected.
- Since:
- 1.10
-
streamUnknownLength
RequestSpec.Body streamUnknownLength(Publisher<? extends io.netty.buffer.ByteBuf> publisher)
Specifies that the request body will be supplied by the given publisher, with an unknown length.The publisher may be subscribed to multiple times, if the request is redirected.
If the length of the content is known, prefer
stream(Publisher, long)
as it is more efficient.- Since:
- 1.10
-
buffer
RequestSpec.Body buffer(io.netty.buffer.ByteBuf byteBuf)
Specifies the request body as a byte buffer.The given byte buffer will not be copied. That is, changes to the byte buffer made after calling this method will affect the body.
- Parameters:
byteBuf
- the intended request body- Returns:
- this
-
bytes
RequestSpec.Body bytes(byte[] bytes)
Specifies the request body as a byte array.The given byte array will not be copied. That is, changes to the byte array made after calling this method will affect the body.
- Parameters:
bytes
- the intended request body- Returns:
- this
-
text
RequestSpec.Body text(CharSequence text)
Specifies the request body as a UTF-8 char sequence.This method is a shorthand for calling
text(CharSequence, java.nio.charset.Charset)
with a UTF-8 charset.- Parameters:
text
- the request body- Returns:
- this
- See Also:
text(CharSequence, java.nio.charset.Charset)
-
text
RequestSpec.Body text(CharSequence text, Charset charset)
Specifies the request body as a char sequence of the given charset.Unlike other methods of this interface, this method will set the request
"Content-Type"
header if it has not already been set. If it has not been set, it will be set to"text/plain;charset=«charset»"
.- Parameters:
text
- the request bodycharset
- the charset of the request body (used to convert the text to bytes)- Returns:
- this
-
-