All Packages Class Hierarchy This Package Previous Next Index
Class HTTPClient.HttpURLConnection
java.lang.Object
|
+----java.net.URLConnection
|
+----java.net.HttpURLConnection
|
+----HTTPClient.HttpURLConnection
- public class HttpURLConnection
- extends HttpURLConnection
- implements GlobalConstants
This class is a wrapper around HTTPConnection providing the interface
defined by java.net.URLConnection and java.net.HttpURLConnection.
This class can be used to replace the HttpClient in the JDK with this
HTTPClient by defining the property
java.protocol.handler.pkgs=HTTPClient
.
- Since:
- V0.3
- Version:
- 0.3 30/01/1998
- Author:
- Ronald Tschalär
-
HttpURLConnection(URL)
- Construct a connection to the specified url.
-
connect()
- Connects to the server (if connection not still kept alive) and
issues the request.
-
disconnect()
- Closes all the connections to this server.
-
getDefaultRequestProperty(String)
- Gets the value for a given default request header.
-
getFollowRedirects()
- Says whether redirection responses are handled automatically or not.
-
getHeaderField(int)
- Gets header value of the n-th header.
-
getHeaderField(String)
- Get the value part of a header.
-
getHeaderFieldDate(String, long)
- Get the value part of a header, interprets it as a date and converts
it to a long representing the number of milliseconds since 1970.
-
getHeaderFieldInt(String, int)
- Get the value part of a header and converts it to an int.
-
getHeaderFieldKey(int)
- Gets header name of the n-th header.
-
getInputStream()
- Gets an input stream from which the data in the response may be read.
-
getOutputStream()
- Gets an output stream which can be used send an entity with the
request.
-
getRequestMethod()
- Return the request method used.
-
getRequestProperty(String)
- Gets the value of a given request header.
-
getResponseCode()
- Get the response code.
-
getResponseMessage()
- Get the response message describing the response code.
-
getURL()
- Gets the url for this connection.
-
setDefaultRequestProperty(String, String)
- Sets an arbitrary default request header.
-
setFollowRedirects(boolean)
- Enables or disables the automatic handling of redirection responses.
-
setIfModifiedSince(long)
- Sets the If-Modified-Since header.
-
setRequestMethod(String)
- Sets the request method (e.g.
-
setRequestProperty(String, String)
- Sets an arbitrary request header.
-
toString()
- produces a string.
-
usingProxy()
- Shows if request are being made through an http proxy or directly.
HttpURLConnection
public HttpURLConnection(URL url) throws UnknownHostException, ProtocolNotSuppException
- Construct a connection to the specified url. A cache of
HTTPConnections is used to maximize the reuse of these across
multiple HttpURLConnections.
The default method is "GET".
- Parameters:
- url - the url of the request
- Throws:
UnknownHostException
- if the host name translation failed
- Throws:
ProtocolNotSuppException
- if the protocol is not supported
setRequestMethod
public void setRequestMethod(String method) throws ProtocolException
- Sets the request method (e.g. "PUT" or "HEAD"). Can only be set
before connect() is called.
- Parameters:
- method - the http method.
- Throws:
ProtocolException
- if already connected.
- Overrides:
- setRequestMethod in class HttpURLConnection
getRequestMethod
public String getRequestMethod()
- Return the request method used.
- Returns:
- the http method.
- Overrides:
- getRequestMethod in class HttpURLConnection
getResponseCode
public int getResponseCode() throws IOException
- Get the response code. Calls connect() if not connected.
- Returns:
- the http response code returned.
- Overrides:
- getResponseCode in class HttpURLConnection
getResponseMessage
public String getResponseMessage() throws IOException
- Get the response message describing the response code. Calls connect()
if not connected.
- Returns:
- the http response message returned with the response code.
- Overrides:
- getResponseMessage in class HttpURLConnection
getHeaderField
public String getHeaderField(String name)
- Get the value part of a header. Calls connect() if not connected.
- Parameters:
- name - the of the header.
- Returns:
- the value of the header, or null if no such header was returned.
- Overrides:
- getHeaderField in class URLConnection
getHeaderFieldInt
public int getHeaderFieldInt(String name,
int def)
- Get the value part of a header and converts it to an int. If the
header does not exist or if its value could not be converted to an
int then the default is returned. Calls connect() if not connected.
- Parameters:
- name - the of the header.
- def - the default value to return in case of an error.
- Returns:
- the value of the header, or null if no such header was returned.
- Overrides:
- getHeaderFieldInt in class URLConnection
getHeaderFieldDate
public long getHeaderFieldDate(String name,
long def)
- Get the value part of a header, interprets it as a date and converts
it to a long representing the number of milliseconds since 1970. If
the header does not exist or if its value could not be converted to a
date then the default is returned. Calls connect() if not connected.
- Parameters:
- name - the of the header.
- def - the default value to return in case of an error.
- Returns:
- the value of the header, or def in case of an error.
- Overrides:
- getHeaderFieldDate in class URLConnection
getHeaderFieldKey
public String getHeaderFieldKey(int n)
- Gets header name of the n-th header. Calls connect() if not connected.
- Parameters:
- n - which header to return.
- Returns:
- the header name, or null if not that many headers.
- Overrides:
- getHeaderFieldKey in class URLConnection
getHeaderField
public String getHeaderField(int n)
- Gets header value of the n-th header. Calls connect() if not connected.
- Parameters:
- n - which header to return.
- Returns:
- the header value, or null if not that many headers.
- Overrides:
- getHeaderField in class URLConnection
getInputStream
public InputStream getInputStream() throws IOException
- Gets an input stream from which the data in the response may be read.
Calls connect() if not connected.
- Returns:
- an InputStream
- Throws:
ProtocolException
- if input not enabled.
- Overrides:
- getInputStream in class URLConnection
- See Also:
- java.net.URLConnection#setDoInput(boolean)
getOutputStream
public OutputStream getOutputStream() throws IOException
- Gets an output stream which can be used send an entity with the
request. Can be called multiple times, in which case always the
same stream is returned.
The default request method changes to "POST" when this method is
called. Cannot be called after connect().
If no Content-type has been set it defaults to
application/x-www-form-urlencoded. Furthermore, if the
Content-type is application/x-www-form-urlencoded then all
output will be collected in a buffer before sending it to the server;
otherwise an HttpOutputStream is used.
- Returns:
- an OutputStream
- Throws:
ProtocolException
- if already connect()'ed, if output is not
enabled or if the request method does not
support output.
- Overrides:
- getOutputStream in class URLConnection
- See Also:
- java.net.URLConnection#setDoOutput(boolean), HttpOutputStream
getURL
public URL getURL()
- Gets the url for this connection. If we're connect()'d and the request
was redirected then the url returned is that of the final request.
- Returns:
- the final url, or null if any exception occured.
- Overrides:
- getURL in class URLConnection
setIfModifiedSince
public void setIfModifiedSince(long time)
- Sets the If-Modified-Since header.
- Parameters:
- time - the number of milliseconds since 1970.
- Overrides:
- setIfModifiedSince in class URLConnection
setRequestProperty
public void setRequestProperty(String name,
String value)
- Sets an arbitrary request header.
- Parameters:
- name - the name of the header.
- value - the value for the header.
- Overrides:
- setRequestProperty in class URLConnection
getRequestProperty
public String getRequestProperty(String name)
- Gets the value of a given request header.
- Parameters:
- name - the name of the header.
- Returns:
- the value part of the header, or null if no such header.
- Overrides:
- getRequestProperty in class URLConnection
setDefaultRequestProperty
public static void setDefaultRequestProperty(String name,
String value)
- Sets an arbitrary default request header. All headers set here are
automatically sent with each request.
- Parameters:
- name - the name of the header.
- value - the value for the header.
getDefaultRequestProperty
public static String getDefaultRequestProperty(String name)
- Gets the value for a given default request header.
- Parameters:
- name - the name of the header.
- Returns:
- the value part of the header, or null if no such header.
setFollowRedirects
public static void setFollowRedirects(boolean set)
- Enables or disables the automatic handling of redirection responses.
- Parameters:
- set - enables automatic redirection handling if true.
getFollowRedirects
public static boolean getFollowRedirects()
- Says whether redirection responses are handled automatically or not.
- Returns:
- true if automatic redirection handling is enabled.
connect
public void connect() throws IOException
- Connects to the server (if connection not still kept alive) and
issues the request.
- Overrides:
- connect in class URLConnection
disconnect
public void disconnect()
- Closes all the connections to this server.
- Overrides:
- disconnect in class HttpURLConnection
usingProxy
public boolean usingProxy()
- Shows if request are being made through an http proxy or directly.
- Returns:
- true if an http proxy is being used.
- Overrides:
- usingProxy in class HttpURLConnection
toString
public String toString()
- produces a string.
- Returns:
- a string containing the HttpURLConnection
- Overrides:
- toString in class URLConnection
All Packages Class Hierarchy This Package Previous Next Index