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 the text(CharSequence) method. If you already have the desired body content as a byte[], use the bytes(byte[]) method.

    • Method Detail

      • 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 than contentLength, 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,
                              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 body
        charset - the charset of the request body (used to convert the text to bytes)
        Returns:
        this