Skip to content

Most visited

Recently visited

navigation

HttpsURLConnection

public abstract class HttpsURLConnection
extends HttpURLConnection

java.lang.Object
   ↳ java.net.URLConnection
     ↳ java.net.HttpURLConnection
       ↳ javax.net.ssl.HttpsURLConnection


HttpsURLConnection extends HttpURLConnection with support for https-specific features.

See http://www.w3.org/pub/WWW/Protocols/ and RFC 2818 for more details on the https specification.

This class uses HostnameVerifier and SSLSocketFactory. There are default implementations defined for both classes. However, the implementations can be replaced on a per-class (static) or per-instance basis. All new HttpsURLConnections instances will be assigned the "default" static values at instance creation, but they can be overriden by calling the appropriate per-instance set method(s) before connecting.

Summary

Inherited constants

From class java.net.HttpURLConnection

Fields

protected HostnameVerifier hostnameVerifier

The hostnameVerifier for this object.

Inherited fields

From class java.net.HttpURLConnection
From class java.net.URLConnection

Protected constructors

HttpsURLConnection(URL url)

Creates an HttpsURLConnection using the URL specified.

Public methods

abstract String getCipherSuite()

Returns the cipher suite in use on this connection.

static HostnameVerifier getDefaultHostnameVerifier()

Gets the default HostnameVerifier that is inherited by new instances of this class.

static SSLSocketFactory getDefaultSSLSocketFactory()

Gets the default static SSLSocketFactory that is inherited by new instances of this class.

HostnameVerifier getHostnameVerifier()

Gets the HostnameVerifier in place on this instance.

abstract Certificate[] getLocalCertificates()

Returns the certificate(s) that were sent to the server during handshaking.

Principal getLocalPrincipal()

Returns the principal that was sent to the server during handshaking.

Principal getPeerPrincipal()

Returns the server's principal which was established as part of defining the session.

SSLSocketFactory getSSLSocketFactory()

Gets the SSL socket factory to be used when creating sockets for secure https URL connections.

abstract Certificate[] getServerCertificates()

Returns the server's certificate chain which was established as part of defining the session.

static void setDefaultHostnameVerifier(HostnameVerifier v)

Sets the default HostnameVerifier inherited by a new instance of this class.

static void setDefaultSSLSocketFactory(SSLSocketFactory sf)

Sets the default SSLSocketFactory inherited by new instances of this class.

void setHostnameVerifier(HostnameVerifier v)

Sets the HostnameVerifier for this instance.

void setSSLSocketFactory(SSLSocketFactory sf)

Sets the SSLSocketFactory to be used when this instance creates sockets for secure https URL connections.

Inherited methods

From class java.net.HttpURLConnection
From class java.net.URLConnection
From class java.lang.Object

Fields

hostnameVerifier

Added in API level 1
HostnameVerifier hostnameVerifier

The hostnameVerifier for this object.

Protected constructors

HttpsURLConnection

Added in API level 1
HttpsURLConnection (URL url)

Creates an HttpsURLConnection using the URL specified.

Parameters
url URL: the URL

Public methods

getCipherSuite

Added in API level 1
String getCipherSuite ()

Returns the cipher suite in use on this connection.

Returns
String the cipher suite
Throws
IllegalStateException if this method is called before the connection has been established.

getDefaultHostnameVerifier

Added in API level 1
HostnameVerifier getDefaultHostnameVerifier ()

Gets the default HostnameVerifier that is inherited by new instances of this class.

Returns
HostnameVerifier the default host name verifier

See also:

getDefaultSSLSocketFactory

Added in API level 1
SSLSocketFactory getDefaultSSLSocketFactory ()

Gets the default static SSLSocketFactory that is inherited by new instances of this class.

The socket factories are used when creating sockets for secure https URL connections.

Returns
SSLSocketFactory the default SSLSocketFactory

See also:

getHostnameVerifier

Added in API level 1
HostnameVerifier getHostnameVerifier ()

Gets the HostnameVerifier in place on this instance.

Returns
HostnameVerifier the host name verifier

See also:

getLocalCertificates

Added in API level 1
Certificate[] getLocalCertificates ()

Returns the certificate(s) that were sent to the server during handshaking.

Note: This method is useful only when using certificate-based cipher suites.

When multiple certificates are available for use in a handshake, the implementation chooses what it considers the "best" certificate chain available, and transmits that to the other side. This method allows the caller to know which certificate chain was actually sent.

Returns
Certificate[] an ordered array of certificates, with the client's own certificate first followed by any certificate authorities. If no certificates were sent, then null is returned.
Throws
IllegalStateException if this method is called before the connection has been established.

See also:

getLocalPrincipal

Added in API level 1
Principal getLocalPrincipal ()

Returns the principal that was sent to the server during handshaking.

Note: Subclasses should override this method. If not overridden, it will default to returning the X500Principal of the end-entity certificate that was sent to the server for certificate-based ciphersuites or, return null for non-certificate based ciphersuites, such as Kerberos.

Returns
Principal the principal sent to the server. Returns an X500Principal of the end-entity certificate for X509-based cipher suites, and KerberosPrincipal for Kerberos cipher suites. If no principal was sent, then null is returned.
Throws
IllegalStateException if this method is called before the connection has been established.

See also:

getPeerPrincipal

Added in API level 1
Principal getPeerPrincipal ()

Returns the server's principal which was established as part of defining the session.

Note: Subclasses should override this method. If not overridden, it will default to returning the X500Principal of the server's end-entity certificate for certificate-based ciphersuites, or throw an SSLPeerUnverifiedException for non-certificate based ciphersuites, such as Kerberos.

Returns
Principal the server's principal. Returns an X500Principal of the end-entity certiticate for X509-based cipher suites, and KerberosPrincipal for Kerberos cipher suites.
Throws
SSLPeerUnverifiedException if the peer was not verified
IllegalStateException if this method is called before the connection has been established.

See also:

getSSLSocketFactory

Added in API level 1
SSLSocketFactory getSSLSocketFactory ()

Gets the SSL socket factory to be used when creating sockets for secure https URL connections.

Returns
SSLSocketFactory the SSLSocketFactory

See also:

getServerCertificates

Added in API level 1
Certificate[] getServerCertificates ()

Returns the server's certificate chain which was established as part of defining the session.

Note: This method can be used only when using certificate-based cipher suites; using it with non-certificate-based cipher suites, such as Kerberos, will throw an SSLPeerUnverifiedException.

Returns
Certificate[] an ordered array of server certificates, with the peer's own certificate first followed by any certificate authorities.
Throws
SSLPeerUnverifiedException if the peer is not verified.
IllegalStateException if this method is called before the connection has been established.

See also:

setDefaultHostnameVerifier

Added in API level 1
void setDefaultHostnameVerifier (HostnameVerifier v)

Sets the default HostnameVerifier inherited by a new instance of this class.

If this method is not called, the default HostnameVerifier assumes the connection should not be permitted.

Parameters
v HostnameVerifier: the default host name verifier
Throws
IllegalArgumentException if the HostnameVerifier parameter is null.
SecurityException if a security manager exists and its checkPermission method does not allow SSLPermission("setHostnameVerifier")

See also:

setDefaultSSLSocketFactory

Added in API level 1
void setDefaultSSLSocketFactory (SSLSocketFactory sf)

Sets the default SSLSocketFactory inherited by new instances of this class.

The socket factories are used when creating sockets for secure https URL connections.

Parameters
sf SSLSocketFactory: the default SSL socket factory
Throws
IllegalArgumentException if the SSLSocketFactory parameter is null.
SecurityException if a security manager exists and its checkSetFactory method does not allow a socket factory to be specified.

See also:

setHostnameVerifier

Added in API level 1
void setHostnameVerifier (HostnameVerifier v)

Sets the HostnameVerifier for this instance.

New instances of this class inherit the default static hostname verifier set by setDefaultHostnameVerifier. Calls to this method replace this object's HostnameVerifier.

Parameters
v HostnameVerifier: the host name verifier
Throws
IllegalArgumentException if the HostnameVerifier parameter is null.

See also:

setSSLSocketFactory

Added in API level 1
void setSSLSocketFactory (SSLSocketFactory sf)

Sets the SSLSocketFactory to be used when this instance creates sockets for secure https URL connections.

New instances of this class inherit the default static SSLSocketFactory set by setDefaultSSLSocketFactory. Calls to this method replace this object's SSLSocketFactory.

Parameters
sf SSLSocketFactory: the SSL socket factory
Throws
IllegalArgumentException if the SSLSocketFactory parameter is null.

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.