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(Action<? super java.io.OutputStream> action)
Specifies the request body by writing to an output stream.RequestSpec.Body
text(java.lang.CharSequence text)
Specifies the request body as a UTF-8 char sequence.RequestSpec.Body
text(java.lang.CharSequence text, java.nio.charset.Charset charset)
Specifies the request body as a char sequence of the given charset.RequestSpec.Body
type(java.lang.CharSequence contentType)
Specifies the"Content-Type"
of the request.
-
-
-
Method Detail
-
type
RequestSpec.Body type(java.lang.CharSequence contentType)
Specifies the"Content-Type"
of the request.Call this method has the same effect as using
RequestSpec.getHeaders()
orRequestSpec.headers(ratpack.func.Action)
to set the"Content-Type"
header.- Parameters:
contentType
- the value of the Content-Type header- Returns:
- this
-
stream
RequestSpec.Body stream(Action<? super java.io.OutputStream> action) throws java.lang.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:
java.lang.Exception
- any thrown by action
-
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(java.lang.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(java.lang.CharSequence text, java.nio.charset.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
-
-