java.lang.Object | +--java.net.URLConnection | +--java.net.HttpURLConnection
Untamed: A URLConnection with support for HTTP-specific features. See the spec for details.
Each HttpURLConnection instance is used to make a single request but the underlying network connection to the HTTP server may be transparently shared by other instances. Calling the close() methods on the InputStream or OutputStream of an HttpURLConnection after a request may free network resources associated with this instance but has no effect on any shared persistent connection. Calling the disconnect() method may close the underlying socket if a persistent connection is otherwise idle at that time.
java.net.HttpURLConnection#disconnect()
protected boolean
instanceFollowRedirects
true
, the protocol will automatically follow redirects.
abstract void
disconnect()
InputStream
getErrorStream()
static boolean
getFollowRedirects()
boolean
indicating
whether or not HTTP redirects (3xx) should
be automatically followed.
boolean
getInstanceFollowRedirects()
HttpURLConnection
's
instanceFollowRedirects
field.
String
getResponseMessage()
static void
setFollowRedirects(boolean set)
void
setInstanceFollowRedirects(boolean followRedirects)
HttpURLConnection
instance.
void
setRequestMethod(String method)
addRequestProperty, connect, getAllowUserInteraction, getContent, getContent, getContentEncoding, getContentHandler, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldInt, getHeaderFieldKey, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setRequestProperty, setUseCaches, toString
protected String method
protected int responseCode
int
representing the three digit HTTP Status-Code.
protected String responseMessage
private static boolean followRedirects
protected boolean instanceFollowRedirects
true
, the protocol will automatically follow redirects.
If false
, the protocol will not automatically follow
redirects.
This field is set by the setInstanceFollowRedirects
method. Its value is returned by the getInstanceFollowRedirects
method.
Its default value is based on the value of the static followRedirects at HttpURLConnection construction time.
java.net.HttpURLConnection#setInstanceFollowRedirects(boolean)
,
java.net.HttpURLConnection#getInstanceFollowRedirects()
,
java.net.HttpURLConnection#setFollowRedirects(boolean)
private static final String[] methods
public static final int HTTP_OK
public static final int HTTP_CREATED
public static final int HTTP_ACCEPTED
public static final int HTTP_NOT_AUTHORITATIVE
public static final int HTTP_NO_CONTENT
public static final int HTTP_RESET
public static final int HTTP_PARTIAL
public static final int HTTP_MULT_CHOICE
public static final int HTTP_MOVED_PERM
public static final int HTTP_MOVED_TEMP
public static final int HTTP_SEE_OTHER
public static final int HTTP_NOT_MODIFIED
public static final int HTTP_USE_PROXY
public static final int HTTP_BAD_REQUEST
public static final int HTTP_UNAUTHORIZED
public static final int HTTP_PAYMENT_REQUIRED
public static final int HTTP_FORBIDDEN
public static final int HTTP_NOT_FOUND
public static final int HTTP_BAD_METHOD
public static final int HTTP_NOT_ACCEPTABLE
public static final int HTTP_PROXY_AUTH
public static final int HTTP_CLIENT_TIMEOUT
public static final int HTTP_CONFLICT
public static final int HTTP_GONE
public static final int HTTP_LENGTH_REQUIRED
public static final int HTTP_PRECON_FAILED
public static final int HTTP_ENTITY_TOO_LARGE
public static final int HTTP_REQ_TOO_LONG
public static final int HTTP_UNSUPPORTED_TYPE
public static final int HTTP_SERVER_ERROR
public static final int HTTP_INTERNAL_ERROR
public static final int HTTP_NOT_IMPLEMENTED
public static final int HTTP_BAD_GATEWAY
public static final int HTTP_UNAVAILABLE
public static final int HTTP_GATEWAY_TIMEOUT
public static final int HTTP_VERSION
protected HttpURLConnection(URL u)
u
- the URLpublic static void setFollowRedirects(boolean set)
If there is a security manager, this method first calls
the security manager's checkSetFactory
method
to ensure the operation is allowed.
This could result in a SecurityException.
set
- a boolean
indicating whether or not
to follow HTTP redirects.SecurityManager.checkSetFactory()
,
getFollowRedirects()
public static boolean getFollowRedirects()
boolean
indicating
whether or not HTTP redirects (3xx) should
be automatically followed.
true
if HTTP redirects should
be automatically followed, false if not.setFollowRedirects(boolean)
public void setInstanceFollowRedirects(boolean followRedirects)
HttpURLConnection
instance.
The default value comes from followRedirects, which defaults to true.
followRedirects
- a boolean
indicating
whether or not to follow HTTP redirects.java.net.HttpURLConnection#instanceFollowRedirects
,
getInstanceFollowRedirects()
public boolean getInstanceFollowRedirects()
HttpURLConnection
's
instanceFollowRedirects
field.
HttpURLConnection
's
instanceFollowRedirects
field.java.net.HttpURLConnection#instanceFollowRedirects
,
setInstanceFollowRedirects(boolean)
public void setRequestMethod(String method) throws ProtocolException
method
- the HTTP method
ProtocolException
getRequestMethod()
public String getRequestMethod()
setRequestMethod(java.lang.String)
public int getResponseCode() throws IOException
HTTP/1.0 200 OK HTTP/1.0 401 UnauthorizedIt will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e., the response is not valid HTTP).
IOException
- if an error occurred connecting to the server.public String getResponseMessage() throws IOException
HTTP/1.0 200 OK HTTP/1.0 404 Not FoundExtracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).
null
IOException
- if an error occurred connecting to the server.public long getHeaderFieldDate(String name, long Default)
getHeaderFieldDate
in class URLConnection
name
- the name of the header field.Default
- a default value.
Default
argument is returned if the field is
missing or malformed.public abstract void disconnect()
public abstract boolean usingProxy()
public Permission getPermission() throws IOException
getPermission
in class URLConnection
IOException
public InputStream getErrorStream()
This 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.