Module bus.http

Class FormBody

java.lang.Object
org.miaixz.bus.http.bodys.RequestBody
org.miaixz.bus.http.bodys.FormBody

public final class FormBody extends RequestBody
An HTTP request body that represents form-encoded data.

This class handles form data encoded in the application/x-www-form-urlencoded format. It provides support for encoding and decoding form field names and values, which are stored as key-value pairs.

Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • size

      public int size()
      Returns the number of form fields.
      Returns:
      The number of fields.
    • encodedName

      public String encodedName(int index)
      Returns the encoded field name at the specified index.
      Parameters:
      index - The index.
      Returns:
      The encoded field name.
    • name

      public String name(int index)
      Returns the decoded field name at the specified index.
      Parameters:
      index - The index.
      Returns:
      The decoded field name.
    • encodedValue

      public String encodedValue(int index)
      Returns the encoded field value at the specified index.
      Parameters:
      index - The index.
      Returns:
      The encoded field value.
    • value

      public String value(int index)
      Returns the decoded field value at the specified index.
      Parameters:
      index - The index.
      Returns:
      The decoded field value.
    • contentType

      public org.miaixz.bus.core.lang.MediaType contentType()
      Returns the media type of this request body.
      Specified by:
      contentType in class RequestBody
      Returns:
      The media type (application/x-www-form-urlencoded).
    • contentLength

      public long contentLength()
      Returns the length of this request body in bytes.
      Overrides:
      contentLength in class RequestBody
      Returns:
      The length of the request body.
    • writeTo

      public void writeTo(org.miaixz.bus.core.io.sink.BufferSink sink) throws IOException
      Writes the content of this request body to the given sink.
      Specified by:
      writeTo in class RequestBody
      Parameters:
      sink - The sink to write to.
      Throws:
      IOException - if an I/O error occurs.