Class UrlEncodedContent

  • All Implemented Interfaces:
    HttpContent, StreamingContent

    public class UrlEncodedContent
    extends AbstractHttpContent
    Implements support for HTTP form content encoding serialization of type application/x-www-form-urlencoded as specified in the HTML 4.0 Specification.

    Sample usage:

      static void setContent(HttpRequest request, Object item) {
        request.setContent(new UrlEncodedContent(item));
      }
     

    Implementation is not thread-safe.

    Since:
    1.0
    Author:
    Yaniv Inbar
    • Constructor Detail

      • UrlEncodedContent

        public UrlEncodedContent​(Object data)
        Parameters:
        data - key name/value data
    • Method Detail

      • writeTo

        public void writeTo​(OutputStream out)
                     throws IOException
        Description copied from interface: StreamingContent
        Writes the byte content to the given output stream.

        Implementations must not close the output stream, and instead should flush the output stream. Some callers may assume that the the output stream has not been closed, and will fail to work if it has been closed.

        Parameters:
        out - output stream
        Throws:
        IOException
      • setMediaType

        public UrlEncodedContent setMediaType​(HttpMediaType mediaType)
        Description copied from class: AbstractHttpContent
        Sets the media type to use for the Content-Type header, or null if unspecified.

        This will also overwrite any previously set parameter of the media type (for example "charset"), and therefore might change other properties as well.

        Overrides:
        setMediaType in class AbstractHttpContent
      • getData

        public final Object getData()
        Returns the key name/value data or null for none.
        Since:
        1.5
      • setData

        public UrlEncodedContent setData​(Object data)
        Sets the key name/value data.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5