public class HttpURLConnection extends HttpURLConnection
| Modifier and Type | Field and Description |
|---|---|
protected Handler |
handler |
protected HttpClient |
http |
protected java.io.PrintStream |
ps |
static java.lang.String |
userAgent |
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, method, responseCode, responseMessage| Modifier | Constructor and Description |
|---|---|
|
HttpURLConnection(java.net.URL u)
this constructor is used by other protocol handlers such as ftp
that want to use http to fetch urls on their behalf.
|
protected |
HttpURLConnection(java.net.URL u,
Handler handler) |
| Modifier and Type | Method and Description |
|---|---|
void |
addRequestProperty(java.lang.String key,
java.lang.String value)
Adds a general request property specified by a
key-value pair.
|
void |
connect() |
void |
disconnect()
Disconnect from the server (public API)
|
int |
getConnectTimeout()
Returns setting for connect timeout.
|
java.io.InputStream |
getErrorStream()
Returns the error stream if the connection failed
but the server sent useful data nonetheless.
|
java.lang.String |
getHeaderField(int n)
Gets a header field by index.
|
java.lang.String |
getHeaderField(java.lang.String name)
Gets a header field by name.
|
java.lang.String |
getHeaderFieldKey(int n)
Gets a header field by index.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getHeaderFields()
Returns an unmodifiable Map of the header fields.
|
java.io.InputStream |
getInputStream() |
protected HttpClient |
getNewHttpClient(java.net.URL url,
int connectTimeout) |
java.io.OutputStream |
getOutputStream() |
int |
getReadTimeout()
Returns setting for read timeout.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getRequestProperties()
Returns an unmodifiable Map of general request
properties for this connection.
|
java.lang.String |
getRequestProperty(java.lang.String key) |
static java.io.InputStream |
openConnectionCheckRedirects(java.net.URLConnection c)
opens a stream allowing redirects only to the same host.
|
protected void |
plainConnect() |
void |
setAuthenticationProperty(java.lang.String key,
java.lang.String value) |
void |
setConnectTimeout(int timeout) |
protected void |
setNewClient(java.net.URL url)
Obtain a HttpsClient object.
|
void |
setReadTimeout(int timeout)
Sets the read timeout to a specified timeout, in
milliseconds.
|
void |
setRequestProperty(java.lang.String key,
java.lang.String value)
Sets request property.
|
boolean |
streaming() |
boolean |
usingProxy()
Indicates if the connection is going through a proxy.
|
getFollowRedirects, getInstanceFollowRedirects, getPermission, getRequestMethod, getResponseCode, getResponseMessage, setChunkedStreamingMode, setFixedLengthStreamingMode, setFixedLengthStreamingMode, setFollowRedirects, setInstanceFollowRedirects, setRequestMethodgetAllowUserInteraction, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getHeaderFieldInt, getHeaderFieldLong, getURL, getUseCaches, setAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setUseCaches, toStringpublic static final java.lang.String userAgent
protected HttpClient http
protected Handler handler
protected java.io.PrintStream ps
public HttpURLConnection(java.net.URL u)
protected HttpURLConnection(java.net.URL u,
Handler handler)
protected void setNewClient(java.net.URL url)
throws java.io.IOException
url - the URL being accessedjava.io.IOExceptionpublic static java.io.InputStream openConnectionCheckRedirects(java.net.URLConnection c)
throws java.io.IOException
java.io.IOExceptionpublic void connect()
throws java.io.IOException
connect in class java.net.URLConnectionjava.io.IOExceptionprotected void plainConnect()
throws java.io.IOException
java.io.IOExceptionprotected HttpClient getNewHttpClient(java.net.URL url, int connectTimeout) throws java.io.IOException
java.io.IOExceptionpublic java.io.OutputStream getOutputStream()
throws java.io.IOException
getOutputStream in class java.net.URLConnectionjava.io.IOExceptionpublic boolean streaming()
public java.io.InputStream getInputStream()
throws java.io.IOException
getInputStream in class java.net.URLConnectionjava.io.IOExceptionpublic java.io.InputStream getErrorStream()
HttpURLConnectionThis method will not cause a connection to be initiated. If the connection was not connected, or if the server did not have an error while connecting or if the server had an error but no error data was sent, this method will return null. This is the default.
getErrorStream in class HttpURLConnectionpublic void disconnect()
disconnect in class HttpURLConnectionpublic boolean usingProxy()
HttpURLConnectionusingProxy in class HttpURLConnectionpublic java.lang.String getHeaderField(java.lang.String name)
getHeaderField in class java.net.URLConnectionname - the name of the header fieldpublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaderFields()
getHeaderFields in class java.net.URLConnectionpublic java.lang.String getHeaderField(int n)
getHeaderField in class HttpURLConnectionn - the index of the header fieldnth header field,
or null if the value does not exist.HttpURLConnection.getHeaderFieldKey(int)public java.lang.String getHeaderFieldKey(int n)
getHeaderFieldKey in class HttpURLConnectionn - the index of the header fieldnth header field,
or null if the key does not exist.public void setRequestProperty(java.lang.String key,
java.lang.String value)
setRequestProperty in class java.net.URLConnectionvalue - the value to be setpublic void addRequestProperty(java.lang.String key,
java.lang.String value)
addRequestProperty in class java.net.URLConnectionkey - the keyword by which the request is known
(e.g., "accept").value - the value associated with it.getRequestProperties()public void setAuthenticationProperty(java.lang.String key,
java.lang.String value)
public java.lang.String getRequestProperty(java.lang.String key)
getRequestProperty in class java.net.URLConnectionpublic java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestProperties()
getRequestProperties in class java.net.URLConnectionjava.lang.IllegalStateException - if already connectedpublic void setConnectTimeout(int timeout)
setConnectTimeout in class java.net.URLConnectionpublic int getConnectTimeout()
0 return implies that the option is disabled (i.e., timeout of infinity).
getConnectTimeout in class java.net.URLConnectionint that indicates the connect timeout
value in millisecondsURLConnection.setConnectTimeout(int),
URLConnection.connect()public void setReadTimeout(int timeout)
Some non-standard implementation of this method ignores the specified timeout. To see the read timeout set, please call getReadTimeout().
setReadTimeout in class java.net.URLConnectiontimeout - an int that specifies the timeout
value to be used in millisecondsjava.lang.IllegalArgumentException - if the timeout parameter is negativeInputStream.read()public int getReadTimeout()
getReadTimeout in class java.net.URLConnectionint that indicates the read timeout
value in millisecondsURLConnection.setReadTimeout(int),
InputStream.read()