public static interface RequestSpec.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 the text(CharSequence)
method.
If you already have the desired body content as a byte[]
, use the bytes(byte[])
method.
Modifier and Type | Method and Description |
---|---|
RequestSpec.Body |
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. |
RequestSpec.Body type(java.lang.CharSequence contentType)
"Content-Type"
of the request.
Call this method has the same effect as using RequestSpec.getHeaders()
or RequestSpec.headers(ratpack.func.Action)
to set the "Content-Type"
header.
contentType
- the value of the Content-Type headerRequestSpec.Body stream(Action<? super java.io.OutputStream> action) throws java.lang.Exception
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[])
.
action
- an action that writes to the request body to thejava.lang.Exception
- any thrown by actionRequestSpec.Body buffer(ByteBuf byteBuf)
The given byte buffer will not be copied. That is, changes to the byte buffer made after calling this method will affect the body.
byteBuf
- the intended request bodyRequestSpec.Body bytes(byte[] bytes)
The given byte array will not be copied. That is, changes to the byte array made after calling this method will affect the body.
bytes
- the intended request bodyRequestSpec.Body text(java.lang.CharSequence text)
This method is a shorthand for calling text(CharSequence, java.nio.charset.Charset)
with a UTF-8 charset.
text
- the request bodytext(CharSequence, java.nio.charset.Charset)
RequestSpec.Body text(java.lang.CharSequence text, java.nio.charset.Charset 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»"
.
text
- the request bodycharset
- the charset of the request body (used to convert the text to bytes)