com.jscape.inet.http

## Class Http

- java.lang.Object
- - com.jscape.inet.http.Http

- All Implemented Interfaces:
    java.io.Serializable
  Direct Known Subclasses:
    Https, HttpSsh

      public class Http
      extends java.lang.Object
      implements java.io.Serializable

  Implements the basic functionality of a HTTP client.

  Example Usage:

       Http http = new Http();

       // build HTTP request
       HttpRequest request = new HttpRequest("http://www.myserver.com");

       // get HTTP response
       try
       {
         HttpResponse response = http.getResponse(request);
         System.out.println(new String(response.getBody()));
       }
       catch(Exception e)
       {
         System.out.println(e);
       }

  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Http()` Constructs a new `Http` instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addHttpListener(HttpListener listener)` Adds an event listener for events implemented by `HttpListener` interface.
    `void` | `clearProxySettings()` Clears proxy server values.
    `java.io.PrintStream` | `getDebugStream()` Gets PrintStream used in reporting debug statements.
    `long` | `getMaxDataSize()` Returns max data size.
    `int` | `getReadBlockSize()` Gets the number of bytes read in each block of data read from server
    `HttpResponse` | `getResponse(HttpFileUpload request)` Gets response to HTTP request.
    `HttpResponse` | `getResponse(HttpRequest request)` Gets response to HTTP request.
    `HttpResponse` | `getResponseToFile(HttpRequest request, java.io.File file)` Gets response to HTTP request and writes contents to file.
    `int` | `getTimeout()` Gets the timeout used when opening a HTTP connection.
    `int` | `getWriteBlockSize()` Gets number of bytes written in each block to server
    `boolean` | `isDebug()` Gets debug level of HTTP session.
    `void` | `removeHttpListener(HttpListener listener)` Removes instance of `HttpListener`.
    `void` | `setDebug(boolean value)` Sets debugging state.
    `void` | `setDebugStream(java.io.PrintStream debugStream)` Sets PrintStream used in reporting debug statements.
    `void` | `setMaxDataSize(long value)` Sets max data size.
    `void` | `setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)` Sets the username and password to use when for authentication with proxy server.
    `void` | `setProxyHost(java.lang.String proxyHostname, int proxyPort)` Sets the proxy hostname and port for this connection.
    `void` | `setProxyType(java.lang.String proxyType)` Sets the proxy type will be used for this connection.
    `void` | `setReadBlockSize(int value)` Sets the number of bytes read in each block of data read from server
    `void` | `setTimeout(int value)` Sets the timeout for opening a HTTP connection.
    `void` | `setWriteBlockSize(int value)` Sets number of bytes written in each block to server

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Http

          public Http()

      Constructs a new `Http` instance.

  - ### Method Detail

    - #### getTimeout

          public int getTimeout()

      Gets the timeout used when opening a HTTP connection. Default of 0ms uses natural timeout of socket.
      Returns:
        timeout in milliseconds

    - #### setTimeout

          public void setTimeout(int value)

      Sets the timeout for opening a HTTP connection. Default of 0ms uses natural timeout of socket.
      Parameters:
        `value` - in milliseconds

    - #### isDebug

          public boolean isDebug()

      Gets debug level of HTTP session. Debug messages are reported to debug stream. Default debug stream is System.out
      Returns:
        `true` if debugging is on
      See Also:
        `setDebugStream(java.io.PrintStream)`

    - #### setDebug

          public void setDebug(boolean value)

      Sets debugging state. All debug statements are reported to debug stream. Default debug stream is System.out
      Parameters:
        `value` - `true` to turn debugging on
      See Also:
        `setDebugStream(java.io.PrintStream)`

    - #### getDebugStream

          public java.io.PrintStream getDebugStream()

      Gets PrintStream used in reporting debug statements. Default PrintStream is System.out
      Returns:
        the PrintStream used for debug statements
      See Also:
        `PrintStream`

    - #### setDebugStream

          public void setDebugStream(java.io.PrintStream debugStream)

      Sets PrintStream used in reporting debug statements. Default PrintStream is System.out
      Parameters:
        `debugStream` - the PrintStream to send debug statements to
      See Also:
        `PrintStream`

    - #### getWriteBlockSize

          public int getWriteBlockSize()

      Gets number of bytes written in each block to server
      Returns:
        block size

    - #### setWriteBlockSize

          public void setWriteBlockSize(int value)

      Sets number of bytes written in each block to server
      Parameters:
        `value` - block size

    - #### getReadBlockSize

          public int getReadBlockSize()

      Gets the number of bytes read in each block of data read from server
      Returns:
        block size

    - #### setReadBlockSize

          public void setReadBlockSize(int value)

      Sets the number of bytes read in each block of data read from server
      Parameters:
        `value` - block size

    - #### getMaxDataSize

          public long getMaxDataSize()

      Returns max data size.
      Returns:
        max data size in bytes

    - #### setMaxDataSize

          public void setMaxDataSize(long value)

      Sets max data size.
      Parameters:
        `value` - the max data size in bytes

    - #### setProxyAuthentication

          public void setProxyAuthentication(java.lang.String proxyUsername,
                                             java.lang.String proxyPassword)

      Sets the username and password to use when for authentication with proxy server. To clear these settings invoke the `#clearProxySettings` method.
      Parameters:
        `proxyUsername` - the proxy username
        `proxyPassword` - the proxy password
      See Also:
        `clearProxySettings()`

    - #### setProxyHost

          public void setProxyHost(java.lang.String proxyHostname,
                                   int proxyPort)

      Sets the proxy hostname and port for this connection. To clear these settings invoke the `#clearProxySettings` method.
      Parameters:
        `proxyHostname` - the hostname or ip address of the proxy server
        `proxyPort` - the port of the proxy server
      See Also:
        `clearProxySettings()`

    - #### setProxyType

          public void setProxyType(java.lang.String proxyType)

      Sets the proxy type will be used for this connection.
      Parameters:
        `proxyType` - The proxy type. Valid values: HTTP, SOCKS5

    - #### clearProxySettings

          public void clearProxySettings()

      Clears proxy server values.

    - #### addHttpListener

          public void addHttpListener(HttpListener listener)

      Adds an event listener for events implemented by `HttpListener` interface.
      Parameters:
        `listener` - an `HttpListener`
      See Also:
        `HttpListener`

    - #### removeHttpListener

          public void removeHttpListener(HttpListener listener)

      Removes instance of `HttpListener`.
      Parameters:
        `listener` - an `HttpListener`
      See Also:
        `HttpListener`

    - #### getResponse

          public HttpResponse getResponse(HttpFileUpload request)
                                   throws HttpException

      Gets response to HTTP request.
      Parameters:
        `request` - the HttpFileUpload to perform
      Returns:
        an `HttpResponse`
      Throws:
        `HttpException` - thrown if an I/O or HTTP related error occurs
      See Also:
        `HttpResponse`, `HttpException`

    - #### getResponse

          public HttpResponse getResponse(HttpRequest request)
                                   throws HttpException

      Gets response to HTTP request.
      Parameters:
        `request` - the HttpRequest to perform
      Returns:
        an `HttpResponse`
      Throws:
        `HttpException` - thrown if an I/O or HTTP related error occurs
      See Also:
        `HttpResponse`, `HttpException`

    - #### getResponseToFile

          public HttpResponse getResponseToFile(HttpRequest request,
                                                java.io.File file)
                                         throws HttpException

      Gets response to HTTP request and writes contents to file.
      Parameters:
        `request` - the HttpRequest to perform
        `file` - the file to write the response to
      Returns:
        the `HttpResponse` written to file
      Throws:
        `HttpException` - thrown if an I/O or HTTP related error occurs
      See Also:
        `HttpResponse`, `HttpException`

Copyright © JSCAPE LLC. 1999-2021. All Rights Reserved