添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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.           Returns a permission object representing the permission necessary to make the connection represented by this object. String getRequestMethod () Get the request method. getResponseCode () Gets the status code from an HTTP response message. String getResponseMessage () Gets the HTTP response message, if any, returned along with the response code from a server. static void setFollowRedirects (boolean set) Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class. setInstanceFollowRedirects (boolean followRedirects) Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this HttpURLConnection instance. setRequestMethod ( String method) Set the method for the URL request, one of: OPTIONS DELETE TRACE are legal, subject to protocol restrictions. abstract  boolean usingProxy () Indicates if the connection is going through a proxy. addRequestProperty , connect , getAllowUserInteraction , getContent , getContent , getContentEncoding , getContentLength , getContentType , getDate , getDefaultAllowUserInteraction , getDefaultUseCaches , getDoInput , getDoOutput , getExpiration , getFileNameMap , getHeaderField , getHeaderFieldInt , getHeaderFields , getIfModifiedSince , getInputStream , getLastModified , getOutputStream , getRequestProperties , getRequestProperty , getURL , getUseCaches , guessContentTypeFromName , guessContentTypeFromStream , setAllowUserInteraction , setContentHandlerFactory , setDefaultAllowUserInteraction , setDefaultUseCaches , setDoInput , setDoOutput , setFileNameMap , setIfModifiedSince , setRequestProperty , setUseCaches , toString protected boolean instanceFollowRedirects
If 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.
See Also:
setInstanceFollowRedirects(boolean) , getInstanceFollowRedirects() , setFollowRedirects(boolean)
public static final int HTTP_NOT_AUTHORITATIVE
HTTP Status-Code 203: Non-Authoritative Information.
See Also:
Constant Field Values
public static final int HTTP_PROXY_AUTH
HTTP Status-Code 407: Proxy Authentication Required.
See Also:
Constant Field Values
public static final int HTTP_ENTITY_TOO_LARGE
HTTP Status-Code 413: Request Entity Too Large.
See Also:
Constant Field Values
public static final int HTTP_UNSUPPORTED_TYPE
HTTP Status-Code 415: Unsupported Media Type.
See Also:
Constant Field Values
Returns the key for the n th header field. Some implementations may treat the 0 th header field as special, i.e. as the status line returned by the HTTP server. In this case, getHeaderField(0) returns the status line, but getHeaderFieldKey(0) returns null.
Overrides:
getHeaderFieldKey in class URLConnection
Parameters:
n - an index, where n >=0.
Returns:
the key for the n th header field, or null if the key does not exist.
Returns the value for the n th header field. Some implementations may treat the 0 th header field as special, i.e. as the status line returned by the HTTP server. This method can be used in conjunction with the getHeaderFieldKey method to iterate through all the headers in the message.
Overrides:
getHeaderField in class URLConnection
Parameters:
n - an index, where n>=0.
Returns:
the value of the n th header field, or null if the value does not exist.
See Also:
getHeaderFieldKey(int)
public static void setFollowRedirects (boolean set)
Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class. True by default. Applets cannot change this variable. 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.
Parameters:
set - a boolean indicating whether or not to follow HTTP redirects.
Throws:
SecurityException - if a security manager exists and its checkSetFactory method doesn't allow the operation.
See Also:
SecurityManager.checkSetFactory() , getFollowRedirects()
setInstanceFollowRedirects public void setInstanceFollowRedirects (boolean followRedirects)
Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this HttpURLConnection instance. The default value comes from followRedirects, which defaults to true.
Parameters:
followRedirects - a boolean indicating whether or not to follow HTTP redirects.
See Also:
instanceFollowRedirects , getInstanceFollowRedirects()
public boolean getInstanceFollowRedirects ()
Returns the value of this HttpURLConnection 's instanceFollowRedirects field.
Returns:
the value of this HttpURLConnection 's instanceFollowRedirects field.
See Also:
instanceFollowRedirects , setInstanceFollowRedirects(boolean)
Parameters:
method - the HTTP method
Throws:
ProtocolException - if the method cannot be reset or if the requested method isn't valid for HTTP.
See Also:
getRequestMethod()
Gets the status code from an HTTP response message. For example, in the case of the following status lines: HTTP/1.0 200 OK HTTP/1.0 401 Unauthorized It 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).
Returns:
the HTTP Status-Code, or -1
Throws:
IOException - if an error occurred connecting to the server.
Gets the HTTP response message, if any, returned along with the response code from a server. From responses like: HTTP/1.0 200 OK HTTP/1.0 404 Not Found Extracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).
Returns:
the HTTP response message, or null
Throws:
IOException - if an error occurred connecting to the server.
Description copied from class: URLConnection
Returns the value of the named field parsed as date. The result is the number of milliseconds since January 1, 1970 GMT represented by the named field. This form of getHeaderField exists because some connection types (e.g., http-ng ) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.
Overrides:
getHeaderFieldDate in class URLConnection
Parameters:
name - the name of the header field.
Default - a default value.
Returns:
the value of the field, parsed as a date. The value of the Default argument is returned if the field is missing or malformed.
Indicates that other requests to the server are unlikely in the near future. Calling disconnect() should not imply that this HttpURLConnection instance can be reused for other requests.
Description copied from class: URLConnection
Returns a permission object representing the permission necessary to make the connection represented by this object. This method returns null if no permission is required to make the connection. By default, this method returns java.security.AllPermission . Subclasses should override this method and return the permission that best represents the permission required to make a a connection to the URL. For example, a URLConnection representing a file: URL would return a java.io.FilePermission object.

The permission returned may dependent upon the state of the connection. For example, the permission before connecting may be different from that after connecting. For example, an HTTP sever, say foo.com, may redirect the connection to a different host, say bar.com. Before connecting the permission returned by the connection will represent the permission needed to connect to foo.com, while the permission returned after connecting will be to bar.com.

Permissions are generally used for two purposes: to protect caches of objects obtained through URLConnections, and to check the right of a recipient to learn about a particular URL. In the first case, the permission should be obtained after the object has been obtained. For example, in an HTTP connection, this will represent the permission to connect to the host from which the data was ultimately fetched. In the second case, the permission should be obtained and tested before connecting.

Overrides:
getPermission in class URLConnection
Returns:
the permission object representing the permission necessary to make the connection represented by this URLConnection.
Throws:
IOException - if the computation of the permission requires network or file I/O and an exception occurs while computing it.
Returns the error stream if the connection failed but the server sent useful data nonetheless. The typical example is when an HTTP server responds with a 404, which will cause a FileNotFoundException to be thrown in connect, but the server sent an HTML help page with suggestions as to what to do.

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.

Returns:
an error stream if any, null if there have been no errors, the connection is not connected or the server sent no useful data.