Class HttpUtils


  • public abstract class HttpUtils
    extends Object
    Provides convenience methods for use the HTTP POST method.
    Author:
    Lawrence Karnowski
    • Field Detail

      • DEFAULT_POST_BUFFER_SIZE

        public static final int DEFAULT_POST_BUFFER_SIZE
        Default buffer size for reading data. (Default is one kilobyte.)
        See Also:
        Constant Field Values
      • DEFAULT_CONNECT_TIMEOUT

        public static final int DEFAULT_CONNECT_TIMEOUT
        See Also:
        Constant Field Values
    • Constructor Detail

      • HttpUtils

        public HttpUtils()
    • Method Detail

      • post

        public static InputStream post​(URL url,
                                       InputStream dataStream)
                                throws IOException
        Post a given InputStream s data to a URL.
        Parameters:
        url - the URL to post to
        dataStream - an input stream containing the data to send
        Returns:
        An InputStream that the programmer can read from to get the HTTP server's response.
        Throws:
        IOException - if any.
      • post

        public static InputStream post​(URL url,
                                       InputStream dataStream,
                                       String username,
                                       String password)
                                throws IOException
        Post a given InputStream s data to a URL using BASIC authentication and the given username and password.
        Parameters:
        url - the URL to post to
        dataStream - an input stream containing the data to send
        username - the username to use in the BASIC authentication
        password - the password to use in the BASIC authentication
        Returns:
        An InputStream that the programmer can read from to get the HTTP server's response.
        Throws:
        IOException - if any.
      • post

        public static InputStream post​(URL url,
                                       InputStream dataStream,
                                       String username,
                                       String password,
                                       int bufSize,
                                       int timeout)
                                throws IOException
        Post a given InputStream s data to a URL using BASIC authentication, the given username and password, and a buffer size.
        Parameters:
        url - the URL to post to
        dataStream - an input stream containing the data to send
        username - the username to use in the BASIC authentication
        password - the password to use in the BASIC authentication
        bufSize - the size of the buffer to read from dataStream and write to the HTTP server
        Returns:
        An InputStream that the programmer can read from to get the HTTP server's response.
        Throws:
        IOException - if any.
      • post

        public static InputStream post​(URL url,
                                       Reader dataReader,
                                       String username,
                                       String password,
                                       int bufSize,
                                       int timeout)
                                throws IOException
        Post a given Reader s data to a URL using BASIC authentication, the given username and password, and a buffer size.
        Parameters:
        url - the URL to post to
        dataReader - an input reader containing the data to send
        username - the username to use in the BASIC authentication
        password - the password to use in the BASIC authentication
        bufSize - the size of the buffer to read from dataStream and write to the HTTP server
        Returns:
        An InputStream that the programmer can read from to get the HTTP server's response.
        Throws:
        IOException - if any.