Name

HttpURLConnection

Synopsis

This class is a specialization of URLConnection. An instance of this class is returned when the openConnection( ) method is called for a URL object that uses the HTTP protocol. The many constants defined by this class are the status codes returned by HTTP servers. setRequestMethod( ) specifies what kind of HTTP request is made. The contents of this request must be sent through the OutputStream returned by the getOutputStream( ) method of the superclass. Once an HTTP request has been sent, getResponseCode( ) returns the HTTP server’s response code as an integer, and getResponseMessage( ) returns the server’s response message. The disconnect( ) method closes the connection. The static setFollowRedirects( ) specifies whether URL connections that use the HTTP protocol should automatically follow redirect responses sent by HTTP servers. In order to successfully use this class, you need to understand the details of the HTTP protocol.

java.net.HttpURLConnection

Figure 12-5. java.net.HttpURLConnection

public abstract class HttpURLConnection extends URLConnection {
// Protected Constructors
     protected HttpURLConnection(URL u);  
// Public Constants
     public static final int HTTP_ACCEPTED;         =202
     public static final int HTTP_BAD_GATEWAY;      =502
     public static final int HTTP_BAD_METHOD;       =405
     public static final int HTTP_BAD_REQUEST;      =400
     public static final int HTTP_CLIENT_TIMEOUT;   =408

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.