com.jscape.inet.http

## Class HttpRequest

- java.lang.Object
- - com.jscape.inet.mime.MimeMessage
  - - com.jscape.inet.http.HttpRequest

- All Implemented Interfaces:
    java.io.Serializable
  Direct Known Subclasses:
    HttpFileUpload

      public class HttpRequest
      extends MimeMessage
      implements java.io.Serializable

  Creates the properties of an HTTP request.

  Example Usage:

       HttpRequest request = new HttpRequest("http://www.myserver.com","GET");
       request.addParameter(new HttpParameter("username","jsmith"));
       request.addParameter(new HttpParameter("password","secret"));

  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpRequest(java.lang.String url)` Creates a new `HttpRequest` instance using default GET request method.
    `HttpRequest(java.lang.String url, java.lang.String method)` Creates a new `HttpRequest` instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addCookie(java.lang.String name, java.lang.String value)` Adds cookie name/value pair to this `HttpRequest`
    `void` | `addHeader(MimeHeader header)` Adds MIME header to this `HttpRequest`.
    `void` | `addHeader(java.lang.String name, java.lang.String value)` Adds MIME header to this `HttpRequest`.
    `void` | `addParameter(HttpParameter parameter)` Adds a query parameter to HTTP request.
    `void` | `addParameter(java.lang.String name, java.lang.String value)` Adds a query parameter to HTTP request.
    `void` | `addReplaceHeader(MimeHeader header)` Adds MIME header to this `HttpRequest`, replacing existing header if found.
    `void` | `addReplaceHeader(java.lang.String name, java.lang.String value)` Adds MIME header to this `HttpRequest`, replacing existing header if found.
    `void` | `addReplaceParameter(HttpParameter parameter)` Adds a query parameter to HTTP request replacing any other parameters with same name.
    `void` | `addReplaceParameter(java.lang.String name, java.lang.String value)` Adds a query parameter to HTTP request replacing any other parameters with same name.
    `void` | `clearCookies()` Clears all cookies from HTTP request
    `void` | `clearParameters()` Clears all parameters from HTTP request
    `java.lang.String` | `getHttpVersion()` Gets the HTTP version number sent in this `HttpRequest`.
    `byte[]` | `getMessage()` Gets contents of this `HttpRequest`.
    `java.lang.String` | `getMethod()` Gets the request method used in HTTP request.
    `java.util.Enumeration` | `getParameters()` Gets all HTTP parameters to be sent with HTTP request.
    `java.lang.String` | `getProxyHost()` Gets the hostname/ipaddress of the proxy server responsible for handling HTTP requests.
    `int` | `getProxyPort()` Gets the port of HTTP proxy server.
    `java.lang.String` | `getProxyUsername()` Gets the username used in authentication to HTTP proxy server.
    `java.lang.String` | `getURL()` Gets URL of HTTP request.
    `java.lang.String` | `getUserAgent()` Gets User-Agent header of HTTP request.
    `boolean` | `isUTF8()` Gets whether UTF-8 encoding is used when encoding parameters, default is true.
    `void` | `setBasicAuthentication(java.lang.String username, java.lang.String password)` Sets username and password to be used in HTTP Basic Authentication.
    `void` | `setHttpVersion(java.lang.String httpVersion)` Sets the HTTP version number sent in this `HttpRequest`.
    `void` | `setMethod(java.lang.String method)` Sets the request method used in HTTP request.
    `void` | `setProxyHost(java.lang.String proxyHost)` Sets the hostname of the proxy server to be used in HTTP communications.
    `void` | `setProxyLogin(java.lang.String proxyUsername, java.lang.String proxyPassword)` Sets the username and password used in authentication to HTTP proxy server.
    `void` | `setProxyPort(int proxyPort)` Sets the port to be used when communicating with an HTTP proxy server.
    `void` | `setURL(java.lang.String urlStr)` Sets URL of HTTP request.
    `void` | `setUserAgent(java.lang.String userAgent)` Sets the User-Agent header of a HTTP request.
    `void` | `setUTF8(boolean b)` Sets whether UTF-8 encoding is used when encoding parameters, default is true.

    - ### Methods inherited from class com.jscape.inet.mime.MimeMessage

      `addPart, getBody, getBodyAsFile, getBodyData, getBoundary, getContentTransferEncoding, getContentType, getHeader, getHeaders, getHeaders, getHeaderValue, getPart, getParts, getRawBodyData, removeHeader, removePart, removeParts, setBody, setBody, setBody, setBody, setBodyAsFile, setContentType`

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

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

- - ### Constructor Detail

    - #### HttpRequest

          public HttpRequest(java.lang.String url)
                      throws HttpException

      Creates a new `HttpRequest` instance using default GET request method. Any parameters provided in the URL must be URL encoded Additional parameters added using addParameter methods will be appended to any existing parameters in the URL.
      Parameters:
        `url` - the URL to retrieve
      Throws:
        `HttpException` - if a MIME related error occurs

    - #### HttpRequest

          public HttpRequest(java.lang.String url,
                             java.lang.String method)
                      throws HttpException

      Creates a new `HttpRequest` instance. Any parameters provided in the URL for a GET request must be URL encoded. Additional parameters added using addParameter methods will be appended to any existing parameters in the URL.
      Parameters:
        `url` - the URL to retrieve
        `method` - the request method to use GET or POST
      Throws:
        `HttpException` - if a MIME related parsing error occurs

  - ### Method Detail

    - #### setProxyHost

          public void setProxyHost(java.lang.String proxyHost)

      Sets the hostname of the proxy server to be used in HTTP communications. Hostname must be a fully qualified domain name or dotted ipaddress. For example proxy.domain.com or 10.0.0.1
      Parameters:
        `proxyHost` - the hostname or ipaddress of the proxy server

    - #### getProxyHost

          public java.lang.String getProxyHost()

      Gets the hostname/ipaddress of the proxy server responsible for handling HTTP requests.
      Returns:
        the hostname or ipaddress of the proxy server

    - #### setProxyPort

          public void setProxyPort(int proxyPort)

      Sets the port to be used when communicating with an HTTP proxy server.
      Parameters:
        `proxyPort` - port of listening HTTP proxy server

    - #### getProxyPort

          public int getProxyPort()

      Gets the port of HTTP proxy server.
      Returns:
        port of listening HTTP proxy server

    - #### getProxyUsername

          public java.lang.String getProxyUsername()

      Gets the username used in authentication to HTTP proxy server.
      Returns:
        username used in proxy authentication

    - #### setProxyLogin

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

      Sets the username and password used in authentication to HTTP proxy server.
      Parameters:
        `proxyUsername` - username used in proxy authentication
        `proxyPassword` - password used in proxy authentication

    - #### addCookie

          public void addCookie(java.lang.String name,
                                java.lang.String value)

      Adds cookie name/value pair to this `HttpRequest`
      Parameters:
        `name` - the cookie name
        `value` - the cookie value

    - #### addHeader

          public void addHeader(MimeHeader header)

      Adds MIME header to this `HttpRequest`.
      Overrides:
        `addHeader` in class `MimeMessage`
      Parameters:
        `header` - a `MimeHeader`

    - #### addHeader

          public void addHeader(java.lang.String name,
                                java.lang.String value)
                         throws MimeException

      Adds MIME header to this `HttpRequest`.
      Overrides:
        `addHeader` in class `MimeMessage`
      Parameters:
        `name` - the header name
        `value` - the header value
      Throws:
        `MimeException` - if a MIME related parsing error occurs

    - #### addReplaceHeader

          public void addReplaceHeader(MimeHeader header)

      Adds MIME header to this `HttpRequest`, replacing existing header if found.
      Overrides:
        `addReplaceHeader` in class `MimeMessage`
      Parameters:
        `header` - a `MimeHeader`

    - #### addReplaceHeader

          public void addReplaceHeader(java.lang.String name,
                                       java.lang.String value)
                                throws MimeException

      Adds MIME header to this `HttpRequest`, replacing existing header if found.
      Overrides:
        `addReplaceHeader` in class `MimeMessage`
      Parameters:
        `name` - the header name
        `value` - the header value
      Throws:
        `MimeException` - if a MIME related parsing error occurs

    - #### addParameter

          public void addParameter(HttpParameter parameter)

      Adds a query parameter to HTTP request. HTTP query parameters are typically used in submitting form data for processing by a CGI or servlet resident on the HTTP server. Names of query parameters need not be unique.
      Parameters:
        `parameter` - the `HttpParameter` to add
      See Also:
        `HttpParameter`

    - #### addReplaceParameter

          public void addReplaceParameter(HttpParameter parameter)

      Adds a query parameter to HTTP request replacing any other parameters with same name. HTTP query parameters are typically used in submitting form data for processing by a CGI or servlet resident on the HTTP server. Names of query parameters need not be unique.
      Parameters:
        `parameter` - the HttpParameter to add or replace

    - #### addReplaceParameter

          public void addReplaceParameter(java.lang.String name,
                                          java.lang.String value)

      Adds a query parameter to HTTP request replacing any other parameters with same name. HTTP query parameters are typically used in submitting form data for processing by a CGI or servlet resident on the HTTP server. Names of query parameters need not be unique.
      Parameters:
        `name` - the name of the parameter to add.
        `value` - the value of the parameter to add.

    - #### addParameter

          public void addParameter(java.lang.String name,
                                   java.lang.String value)

      Adds a query parameter to HTTP request. HTTP query parameters are typically used in submitting form data for processing by a CGI or servlet resident on the HTTP server. Names of query parameters need not be unique.
      Parameters:
        `name` - the name of the parameter to add.
        `value` - the value of the parameter to add.

    - #### clearParameters

          public void clearParameters()

      Clears all parameters from HTTP request

    - #### clearCookies

          public void clearCookies()

      Clears all cookies from HTTP request

    - #### getParameters

          public java.util.Enumeration getParameters()

      Gets all HTTP parameters to be sent with HTTP request. HTTP query parameters are typically used in submitting form data for processing by a CGI or servlet resident on the HTTP server. Names of query parameters need not be unique.
      Returns:
        an `Enumeration` of `HttpParameter`
      See Also:
        `HttpParameter`

    - #### setBasicAuthentication

          public void setBasicAuthentication(java.lang.String username,
                                             java.lang.String password)
                                      throws HttpException

      Sets username and password to be used in HTTP Basic Authentication. HTTP Basic Authentication is used when attempting to access a username/password protected URL.
      Parameters:
        `username` - the username used in HTTP Basic Authentication
        `password` - the password used in HTTP Basic Authentication
      Throws:
        `HttpException` - if a MIME related parsing error occurs

    - #### setUserAgent

          public void setUserAgent(java.lang.String userAgent)
                            throws HttpException

      Sets the User-Agent header of a HTTP request. The User-Agent header is used in identifying the type of client making the HTTP request. The User-Agent header typically contains the name and version of the client software.
      Parameters:
        `userAgent` - the user agent
      Throws:
        `HttpException` - if a MIME related parsing error occurs

    - #### getUserAgent

          public java.lang.String getUserAgent()

      Gets User-Agent header of HTTP request.
      Returns:
        the user agent

    - #### setMethod

          public void setMethod(java.lang.String method)

      Sets the request method used in HTTP request. Valid request methods are GET, POST and PUT, default is GET. The GET method appends all HTTP parameters to the end of the URL when making a HTTP request and has a 4K limit on the amount of data which may be passed. The POST method effectively hides this data in the HTTP request headers and has no data size limit. The PUT method is used in HTTP 1.1 compliant server which support the PUT request.
      Parameters:
        `method` - request method used in HTTP request

    - #### getMethod

          public java.lang.String getMethod()

      Gets the request method used in HTTP request. Valid request methods are GET, POST and PUT, default is GET. The GET method appends all HTTP parameters to the end of the URL when making a HTTP request and has a 4K limit on the amount of data which may be passed. The POST method effectively hides this data in the HTTP request headers and has no data size limit. The PUT method is used in HTTP 1.1 compliant server which support the PUT request.
      Returns:
        the request method used in HTTP request

    - #### setURL

          public void setURL(java.lang.String urlStr)

      Sets URL of HTTP request. Example of a valid URL is http://www.myserver.com/file.html
      Any parameters provided in the URL for a GET request must be URL encoded. Additional parameters added using addParameter methods will be appended to any existing parameters in the URL.
      Parameters:
        `urlStr` - the URL of HTTP request

    - #### getURL

          public java.lang.String getURL()

      Gets URL of HTTP request.
      Returns:
        the URL of HTTP request

    - #### getMessage

          public byte[] getMessage()
                            throws MimeException

      Gets contents of this `HttpRequest`. Contents include all MIME message headers, body and any parts. If request method is POST then required Content-Type and Content-Length headers are added automatically unless already defined using `MimeMessage#addHeader` method.
      Overrides:
        `getMessage` in class `MimeMessage`
      Returns:
        message contents
      Throws:
        `MimeException` - if a MIME related error occurs while building message contents
      See Also:
        `MimeMessage.addHeader(com.jscape.inet.mime.MimeHeader)`

    - #### getHttpVersion

          public java.lang.String getHttpVersion()

      Gets the HTTP version number sent in this `HttpRequest`. Default value is 1.0
      Returns:
        the HTTP version number

    - #### setHttpVersion

          public void setHttpVersion(java.lang.String httpVersion)

      Sets the HTTP version number sent in this `HttpRequest`. Default value is 1.0
      Parameters:
        `httpVersion` - the HTTP version number

    - #### isUTF8

          public boolean isUTF8()

      Gets whether UTF-8 encoding is used when encoding parameters, default is true.
      Returns:
        true if UTF-8 encoding is enabled, false otherwise

    - #### setUTF8

          public void setUTF8(boolean b)

      Sets whether UTF-8 encoding is used when encoding parameters, default is true.
      Parameters:
        `b` - true if UTF-8 encoding is enabled, false otherwise

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