HttpURLConnection (HttpClient Library (Version 3.1))
Date: 2016-03-09

org.apache.commons.httpclient.util

## Class HttpURLConnection

- java.lang.Object
- - java.net.URLConnection
  - - java.net.HttpURLConnection
    - - org.apache.commons.httpclient.util.HttpURLConnection

-     public class HttpURLConnection
      extends java.net.HttpURLConnection

  Provides a `HttpURLConnection` wrapper around HttpClient's `HttpMethod`. This allows existing code to easily switch to HttpClieht without breaking existing interfaces using the JDK `HttpURLConnection`. Note 1: The current implementations wraps only a connected `HttpMethod`, ie a method that has alreayd been used to connect to an HTTP server. Note 2: It is a best try effort as different version of the JDK have different behaviours for `HttpURLConnection` (And I'm not even including the numerous `HttpURLConnection` bugs!).
  Since:
    2.0
  Version:
    $Id: HttpURLConnection.java 480424 2006-11-29 05:56:49Z bayard $
  Author:
    Vincent Massol, Jeff Dever, Mike Bowler

- - ### Field Summary

    - ### Fields inherited from class java.net.HttpURLConnection

      `chunkLength, fixedContentLength, fixedContentLengthLong, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, responseCode, responseMessage`

    - ### Fields inherited from class java.net.URLConnection

      `allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, useCaches`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `HttpURLConnection(HttpMethod method, java.net.URL url)` Creates an `HttpURLConnection` from a `HttpMethod`.
    `protected` | `HttpURLConnection(java.net.URL url)` Create an instance.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `connect()` Not available: the data must have already been retrieved.
    `void` | `disconnect()` Not yet implemented.
    `boolean` | `getAllowUserInteraction()` Not yet implemented.
    `java.lang.Object` | `getContent()` Not yet implemented.
    `java.lang.Object` | `getContent(java.lang.Class[] classes)` Not yet implemented.
    `boolean` | `getDefaultUseCaches()` Not available: the data must have already been retrieved.
    `boolean` | `getDoInput()` Not yet implemented.
    `boolean` | `getDoOutput()` Not yet implemented.
    `java.io.InputStream` | `getErrorStream()` Not yet implemented.
    `java.lang.String` | `getHeaderField(int position)` Return the header field at the specified position
    `java.lang.String` | `getHeaderField(java.lang.String name)` Return the header field
    `java.lang.String` | `getHeaderFieldKey(int keyPosition)` Return the header field key
    `long` | `getIfModifiedSince()` Not yet implemented.
    `java.io.InputStream` | `getInputStream()` Gets an input stream for the HttpMethod response body.
    `boolean` | `getInstanceFollowRedirects()` Not yet implemented.
    `java.io.OutputStream` | `getOutputStream()`
    `java.security.Permission` | `getPermission()` Not yet implemented.
    `java.lang.String` | `getRequestMethod()` Return the request method.
    `java.lang.String` | `getRequestProperty(java.lang.String key)` Not yet implemented.
    `int` | `getResponseCode()` Return the response code.
    `java.lang.String` | `getResponseMessage()` Return the response message
    `java.net.URL` | `getURL()` Return the URL
    `boolean` | `getUseCaches()` Not yet implemented.
    `void` | `setAllowUserInteraction(boolean isAllowInteraction)` Not available: the data must have already been retrieved.
    `void` | `setDefaultUseCaches(boolean isUsingCaches)` Not available: the data must have already been retrieved.
    `void` | `setDoInput(boolean isInput)` Not available: the data must have already been retrieved.
    `void` | `setDoOutput(boolean isOutput)` Not available: the data must have already been retrieved.
    `void` | `setIfModifiedSince(long modificationDate)` Not available: the data must have already been retrieved.
    `void` | `setInstanceFollowRedirects(boolean isFollowingRedirects)` Not available: the data must have already been retrieved.
    `void` | `setRequestMethod(java.lang.String method)` Not available: the data must have already been retrieved.
    `void` | `setRequestProperty(java.lang.String key, java.lang.String value)` Not available: the data must have already been retrieved.
    `void` | `setUseCaches(boolean isUsingCaches)` Not available: the data must have already been retrieved.
    `boolean` | `usingProxy()` Not yet implemented.

    - ### Methods inherited from class java.net.HttpURLConnection

      `getFollowRedirects, getHeaderFieldDate, setChunkedStreamingMode, setFixedLengthStreamingMode, setFixedLengthStreamingMode, setFollowRedirects`

    - ### Methods inherited from class java.net.URLConnection

      `addRequestProperty, getConnectTimeout, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getExpiration, getFileNameMap, getHeaderFieldInt, getHeaderFieldLong, getHeaderFields, getLastModified, getReadTimeout, getRequestProperties, guessContentTypeFromName, guessContentTypeFromStream, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setFileNameMap, setReadTimeout, toString`

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### HttpURLConnection

          public HttpURLConnection(HttpMethod method,
                           java.net.URL url)

      Creates an `HttpURLConnection` from a `HttpMethod`.
      Parameters:
        `method` - the theMethod that was used to connect to the HTTP server and which contains the returned data.
        `url` - the URL to which we are connected (includes query string)

    - #### HttpURLConnection

          protected HttpURLConnection(java.net.URL url)

      Create an instance.
      Parameters:
        `url` - The URL.
      See Also:
        `HttpURLConnection.HttpURLConnection(URL)`

  - ### Method Detail

    - #### getInputStream

          public java.io.InputStream getInputStream()
                                             throws java.io.IOException

      Gets an input stream for the HttpMethod response body.
      Overrides:
        `getInputStream` in class `java.net.URLConnection`
      Returns:
        The input stream.
      Throws:
        `java.io.IOException` - If an IO problem occurs.
      See Also:
        `URLConnection.getInputStream()`, `HttpMethod.getResponseBodyAsStream()`

    - #### getErrorStream

          public java.io.InputStream getErrorStream()

      Not yet implemented. Return the error stream.
      Overrides:
        `getErrorStream` in class `java.net.HttpURLConnection`
      See Also:
        `HttpURLConnection.getErrorStream()`

    - #### disconnect

          public void disconnect()

      Not yet implemented.
      Specified by:
        `disconnect` in class `java.net.HttpURLConnection`
      See Also:
        `HttpURLConnection.disconnect()`

    - #### connect

          public void connect()
                       throws java.io.IOException

      Not available: the data must have already been retrieved.
      Specified by:
        `connect` in class `java.net.URLConnection`
      Throws:
        `java.io.IOException` - If an IO problem occurs.
      See Also:
        `URLConnection.connect()`

    - #### usingProxy

          public boolean usingProxy()

      Not yet implemented.
      Specified by:
        `usingProxy` in class `java.net.HttpURLConnection`
      Returns:
        true if we are using a proxy.
      See Also:
        `HttpURLConnection.usingProxy()`

    - #### getRequestMethod

          public java.lang.String getRequestMethod()

      Return the request method.
      Overrides:
        `getRequestMethod` in class `java.net.HttpURLConnection`
      Returns:
        The request method.
      See Also:
        `HttpURLConnection.getRequestMethod()`, `HttpMethod.getName()`

    - #### getResponseCode

          public int getResponseCode()
                              throws java.io.IOException

      Return the response code.
      Overrides:
        `getResponseCode` in class `java.net.HttpURLConnection`
      Returns:
        The response code.
      Throws:
        `java.io.IOException` - If an IO problem occurs.
      See Also:
        `HttpURLConnection.getResponseCode()`, `HttpMethod.getStatusCode()`

    - #### getResponseMessage

          public java.lang.String getResponseMessage()
                                              throws java.io.IOException

      Return the response message
      Overrides:
        `getResponseMessage` in class `java.net.HttpURLConnection`
      Returns:
        The response message
      Throws:
        `java.io.IOException` - If an IO problem occurs.
      See Also:
        `HttpURLConnection.getResponseMessage()`, `HttpMethod.getStatusText()`

    - #### getHeaderField

          public java.lang.String getHeaderField(java.lang.String name)

      Return the header field
      Overrides:
        `getHeaderField` in class `java.net.URLConnection`
      Parameters:
        `name` - the name of the header
      Returns:
        the header field.
      See Also:
        `URLConnection.getHeaderField(String)`, `HttpMethod.getResponseHeaders()`

    - #### getHeaderFieldKey

          public java.lang.String getHeaderFieldKey(int keyPosition)

      Return the header field key
      Overrides:
        `getHeaderFieldKey` in class `java.net.HttpURLConnection`
      Parameters:
        `keyPosition` - The key position
      Returns:
        The header field key.
      See Also:
        `HttpURLConnection.getHeaderFieldKey(int)`, `HttpMethod.getResponseHeaders()`

    - #### getHeaderField

          public java.lang.String getHeaderField(int position)

      Return the header field at the specified position
      Overrides:
        `getHeaderField` in class `java.net.HttpURLConnection`
      Parameters:
        `position` - The position
      Returns:
        The header field.
      See Also:
        `HttpURLConnection.getHeaderField(int)`, `HttpMethod.getResponseHeaders()`

    - #### getURL

          public java.net.URL getURL()

      Return the URL
      Overrides:
        `getURL` in class `java.net.URLConnection`
      Returns:
        The URL.
      See Also:
        `URLConnection.getURL()`

    - #### setInstanceFollowRedirects

          public void setInstanceFollowRedirects(boolean isFollowingRedirects)

      Not available: the data must have already been retrieved.
      Overrides:
        `setInstanceFollowRedirects` in class `java.net.HttpURLConnection`

    - #### getInstanceFollowRedirects

          public boolean getInstanceFollowRedirects()

      Not yet implemented.
      Overrides:
        `getInstanceFollowRedirects` in class `java.net.HttpURLConnection`

    - #### setRequestMethod

          public void setRequestMethod(java.lang.String method)
                                throws java.net.ProtocolException

      Not available: the data must have already been retrieved.
      Overrides:
        `setRequestMethod` in class `java.net.HttpURLConnection`
      Throws:
        `java.net.ProtocolException`
      See Also:
        `HttpURLConnection.setRequestMethod(String)`

    - #### getPermission

          public java.security.Permission getPermission()
                                                 throws java.io.IOException

      Not yet implemented.
      Overrides:
        `getPermission` in class `java.net.HttpURLConnection`
      Throws:
        `java.io.IOException`
      See Also:
        `HttpURLConnection.getPermission()`

    - #### getContent

          public java.lang.Object getContent()
                                      throws java.io.IOException

      Not yet implemented.
      Overrides:
        `getContent` in class `java.net.URLConnection`
      Throws:
        `java.io.IOException`
      See Also:
        `URLConnection.getContent()`

    - #### getContent

          public java.lang.Object getContent(java.lang.Class[] classes)
                                      throws java.io.IOException

      Not yet implemented.
      Overrides:
        `getContent` in class `java.net.URLConnection`
      Throws:
        `java.io.IOException`

    - #### getOutputStream

          public java.io.OutputStream getOutputStream()
                                               throws java.io.IOException

      Overrides:
        `getOutputStream` in class `java.net.URLConnection`
      Throws:
        `java.io.IOException`
      See Also:
        `URLConnection.getOutputStream()`

    - #### setDoInput

          public void setDoInput(boolean isInput)

      Not available: the data must have already been retrieved.
      Overrides:
        `setDoInput` in class `java.net.URLConnection`
      See Also:
        `URLConnection.setDoInput(boolean)`

    - #### getDoInput

          public boolean getDoInput()

      Not yet implemented.
      Overrides:
        `getDoInput` in class `java.net.URLConnection`
      See Also:
        `URLConnection.getDoInput()`

    - #### setDoOutput

          public void setDoOutput(boolean isOutput)

      Not available: the data must have already been retrieved.
      Overrides:
        `setDoOutput` in class `java.net.URLConnection`
      See Also:
        `URLConnection.setDoOutput(boolean)`

    - #### getDoOutput

          public boolean getDoOutput()

      Not yet implemented.
      Overrides:
        `getDoOutput` in class `java.net.URLConnection`
      See Also:
        `URLConnection.getDoOutput()`

    - #### setAllowUserInteraction

          public void setAllowUserInteraction(boolean isAllowInteraction)

      Not available: the data must have already been retrieved.
      Overrides:
        `setAllowUserInteraction` in class `java.net.URLConnection`
      See Also:
        `URLConnection.setAllowUserInteraction(boolean)`

    - #### getAllowUserInteraction

          public boolean getAllowUserInteraction()

      Not yet implemented.
      Overrides:
        `getAllowUserInteraction` in class `java.net.URLConnection`
      See Also:
        `URLConnection.getAllowUserInteraction()`

    - #### setUseCaches

          public void setUseCaches(boolean isUsingCaches)

      Not available: the data must have already been retrieved.
      Overrides:
        `setUseCaches` in class `java.net.URLConnection`
      See Also:
        `URLConnection.setUseCaches(boolean)`

    - #### getUseCaches

          public boolean getUseCaches()

      Not yet implemented.
      Overrides:
        `getUseCaches` in class `java.net.URLConnection`
      See Also:
        `URLConnection.getUseCaches()`

    - #### setIfModifiedSince

          public void setIfModifiedSince(long modificationDate)

      Not available: the data must have already been retrieved.
      Overrides:
        `setIfModifiedSince` in class `java.net.URLConnection`
      See Also:
        `URLConnection.setIfModifiedSince(long)`

    - #### getIfModifiedSince

          public long getIfModifiedSince()

      Not yet implemented.
      Overrides:
        `getIfModifiedSince` in class `java.net.URLConnection`
      See Also:
        `URLConnection.getIfModifiedSince()`

    - #### getDefaultUseCaches

          public boolean getDefaultUseCaches()

      Not available: the data must have already been retrieved.
      Overrides:
        `getDefaultUseCaches` in class `java.net.URLConnection`
      See Also:
        `URLConnection.getDefaultUseCaches()`

    - #### setDefaultUseCaches

          public void setDefaultUseCaches(boolean isUsingCaches)

      Not available: the data must have already been retrieved.
      Overrides:
        `setDefaultUseCaches` in class `java.net.URLConnection`
      See Also:
        `URLConnection.setDefaultUseCaches(boolean)`

    - #### setRequestProperty

          public void setRequestProperty(java.lang.String key,
                                java.lang.String value)

      Not available: the data must have already been retrieved.
      Overrides:
        `setRequestProperty` in class `java.net.URLConnection`
      See Also:
        `URLConnection.setRequestProperty(String,String)`

    - #### getRequestProperty

          public java.lang.String getRequestProperty(java.lang.String key)

      Not yet implemented.
      Overrides:
        `getRequestProperty` in class `java.net.URLConnection`
      See Also:
        `URLConnection.getRequestProperty(String)`

Copyright (c) 1999-2005 - Apache Software Foundation