No special coding is required to use the replacement URLStreamHandlers/URLConnections
for HTTP and HTTPS.
Simply create a URL object and then open the connection (with openConnection
), as such:
URL myURL = new URL(http://my.server.com/path/to/resource/);
HttpURLConnection myConn = (HttpURLConnection) myURL.openConnection();
InputStream in = myConn.getInputStream();
// read input stream
is a subclass of java.net.HttpURLConnection
. The HttpsURLConnection
is a subclass of javax.net.ssl.HttpsURLConnection
but the methods introduced by javax.net.ssl.HttpsURLConnection
are not implemented. Otherwise, the HttpsURLConnection
subclass operates normally.
subclasses will always consult the Accounts API to locate login credentials for the subject URL. If credentials are present for the URL, then those credentials will be used to authenticate access to the URL.
Parent topic: Developing network aware application logic