Class HttpContent


  • public final class HttpContent
    extends java.lang.Object
    Represents the content of an HTTP request, i.e. the request's body. This class also holds the value of the Content-Type header, which can depend on the body in some cases (e.g. for multipart requests).
    • Method Detail

      • buildFormURLEncodedContent

        public static HttpContent buildFormURLEncodedContent​(java.util.Collection<KeyValuePair<java.lang.String,​java.lang.String>> nameValueCollection)
                                                      throws java.io.IOException
        Builds a new HttpContent for name/value tuples encoded using application/x-www-form-urlencoded MIME type.
        Parameters:
        nameValueCollection - the collection of name/value tuples to encode
        Returns:
        the encoded HttpContent instance
        Throws:
        java.lang.IllegalArgumentException - if nameValueCollection is null
        java.io.IOException
      • stringContent

        public java.lang.String stringContent()
        The request's content, as a string.
      • buildMultipartFormDataContent

        public static HttpContent buildMultipartFormDataContent​(java.util.Collection<KeyValuePair<java.lang.String,​java.lang.Object>> nameValueCollection)
                                                         throws java.io.IOException
        Builds a new HttpContent for name/value tuples encoded using multipart/form-data MIME type.
        Parameters:
        nameValueCollection - the collection of name/value tuples to encode
        Returns:
        the encoded HttpContent instance
        Throws:
        java.lang.IllegalArgumentException - if nameValueCollection is null
        java.io.IOException
      • buildMultipartFormDataContent

        public static HttpContent buildMultipartFormDataContent​(java.util.Collection<KeyValuePair<java.lang.String,​java.lang.Object>> nameValueCollection,
                                                                java.lang.String boundary)
                                                         throws java.io.IOException
        Builds a new HttpContent for name/value tuples encoded using multipart/form-data MIME type.
        Parameters:
        nameValueCollection - the collection of name/value tuples to encode
        boundary - the boundary
        Returns:
        the encoded HttpContent instance
        Throws:
        java.lang.IllegalArgumentException - if nameValueCollection is null
        java.io.IOException
      • byteArrayContent

        public byte[] byteArrayContent()
        The request's content, as a byte array.
      • contentType

        public java.lang.String contentType()
        The value of the Content-Type header.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object