Added in API level 1

HttpsURLConnection

abstract class HttpsURLConnection : HttpURLConnection
kotlin.Any
   ↳ 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
Protected constructors

Creates an HttpsURLConnection using the URL specified.

Public methods
abstract String!

Returns the cipher suite in use on this connection.

open static HostnameVerifier!

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

open static SSLSocketFactory!

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

open HostnameVerifier!

Gets the HostnameVerifier in place on this instance.

abstract Array<Certificate!>!

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

open Principal!

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

open Principal!

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

open SSLSocketFactory!

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

abstract Array<Certificate!>!

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

open static Unit

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

open static Unit

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

open Unit

Sets the HostnameVerifier for this instance.

open Unit

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

Inherited functions
Properties
HostnameVerifier!

The hostnameVerifier for this object.

Inherited properties

Protected constructors

HttpsURLConnection

Added in API level 1
protected HttpsURLConnection(url: URL!)

Creates an HttpsURLConnection using the URL specified.

Parameters
url URL!: the URL

Public methods

getCipherSuite

Added in API level 1
abstract fun getCipherSuite(): String!

Returns the cipher suite in use on this connection.

Return
String! the cipher suite
Exceptions
java.lang.IllegalStateException if this method is called before the connection has been established.

getDefaultHostnameVerifier

Added in API level 1
open static fun getDefaultHostnameVerifier(): HostnameVerifier!

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

Return
HostnameVerifier! the default host name verifier

getDefaultSSLSocketFactory

Added in API level 1
open static fun getDefaultSSLSocketFactory(): SSLSocketFactory!

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.

Return
SSLSocketFactory! the default SSLSocketFactory

getHostnameVerifier

Added in API level 1
open fun getHostnameVerifier(): HostnameVerifier!

Gets the HostnameVerifier in place on this instance.

Return
HostnameVerifier! the host name verifier

getLocalCertificates

Added in API level 1
abstract fun getLocalCertificates(): Array<Certificate!>!

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.

Return
Array<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.
Exceptions
java.lang.IllegalStateException if this method is called before the connection has been established.

getLocalPrincipal

Added in API level 1
open fun getLocalPrincipal(): Principal!

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.

Return
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.
Exceptions
java.lang.IllegalStateException if this method is called before the connection has been established.

getPeerPrincipal

Added in API level 1
open fun getPeerPrincipal(): Principal!

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.

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

getSSLSocketFactory

Added in API level 1
open fun getSSLSocketFactory(): SSLSocketFactory!

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

Return
SSLSocketFactory! the SSLSocketFactory

getServerCertificates

Added in API level 1
abstract fun getServerCertificates(): Array<Certificate!>!

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.

Return
Array<Certificate!>! an ordered array of server certificates, with the peer's own certificate first followed by any certificate authorities.
Exceptions
javax.net.ssl.SSLPeerUnverifiedException if the peer is not verified.
java.lang.IllegalStateException if this method is called before the connection has been established.

setDefaultHostnameVerifier

Added in API level 1
open static fun setDefaultHostnameVerifier(v: HostnameVerifier!): Unit

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

Developers are strongly discouraged from changing the default HostnameVerifier as getDefaultHostnameVerifier() is used by several classes for hostname verification on Android.

User Effect
Android's default TrustManager, as used with Android's default SSLContext, SSLSocketFactory and SSLSocket implementations. The HostnameVerifier is used to verify the peer's certificate hostname after connecting if SSLParameters.setEndpointIdentificationAlgorithm("HTTPS") has been called. Instances use the current default HostnameVerifier at verification time.
android.net.SSLCertificateSocketFactory The current default HostnameVerifier is used from various createSocket methods. See android.net.SSLCertificateSocketFactory for details; for example android.net.SSLCertificateSocketFactory#createSocket(String, int).
Android's default HttpsURLConnection implementation. The HostnameVerifier is used after a successful TLS handshake to verify the URI host against the TLS session server. Instances use the default HostnameVerifier set when they were created unless overridden with setHostnameVerifier(javax.net.ssl.HostnameVerifier). Android's HttpsURLConnection relies on the HostnameVerifier for the entire hostname verification step.

If this method is not called, the default HostnameVerifier will check the hostname according to RFC 2818.

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

setDefaultSSLSocketFactory

Added in API level 1
open static fun setDefaultSSLSocketFactory(sf: SSLSocketFactory!): Unit

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
Exceptions
java.lang.IllegalArgumentException if the SSLSocketFactory parameter is null.
java.lang.SecurityException if a security manager exists and its checkSetFactory method does not allow a socket factory to be specified.

setHostnameVerifier

Added in API level 1
open fun setHostnameVerifier(v: HostnameVerifier!): Unit

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.

Android's HttpsURLConnection relies on the HostnameVerifier for the entire hostname verification step.

Parameters
v HostnameVerifier!: the host name verifier
Exceptions
java.lang.IllegalArgumentException if the HostnameVerifier parameter is null.

setSSLSocketFactory

Added in API level 1
open fun setSSLSocketFactory(sf: SSLSocketFactory!): Unit

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
Exceptions
java.lang.IllegalArgumentException if the SSLSocketFactory parameter is null.
java.lang.SecurityException if a security manager exists and its checkSetFactory method does not allow a socket factory to be specified.

Properties

hostnameVerifier

Added in API level 1
protected var hostnameVerifier: HostnameVerifier!

The hostnameVerifier for this object.