Most visited

Recently visited

Added in API level 1

HttpsURLConnection

public abstract class HttpsURLConnection
extends HttpURLConnection

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


HttpsURLConnection扩展了 HttpURLConnection ,支持https特定功能。

有关https规范的更多详细信息,请参阅 http://www.w3.org/pub/WWW/Protocols/RFC 2818

本课使用HostnameVerifierSSLSocketFactory 为这两个类定义了默认实现。 但是,可以在每个类(静态)或每个实例的基础上替换实现。 所有新的HttpsURLConnection实例将在实例创建时被分配“默认”静态值,但是它们可以通过在connect之前调用适当的每个实例设置方法来重写。

Summary

Inherited constants

From class java.net.HttpURLConnection

Fields

protected HostnameVerifier hostnameVerifier

该对象的 hostnameVerifier

Inherited fields

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

Protected constructors

HttpsURLConnection(URL url)

使用指定的URL创建一个 HttpsURLConnection

Public methods

abstract String getCipherSuite()

返回此连接上使用的密码套件。

static HostnameVerifier getDefaultHostnameVerifier()

获取由此类的新实例继承的默认 HostnameVerifier

static SSLSocketFactory getDefaultSSLSocketFactory()

获取由此类的新实例继承的默认静态 SSLSocketFactory

HostnameVerifier getHostnameVerifier()

在此实例中获取 HostnameVerifier

abstract Certificate[] getLocalCertificates()

返回握手期间发送给服务器的证书。

Principal getLocalPrincipal()

返回握手期间发送给服务器的主体。

Principal getPeerPrincipal()

返回作为定义会话一部分而建立的服务器主体。

SSLSocketFactory getSSLSocketFactory()

在为安全https URL连接创建套接字时获取SSL套接字工厂。

abstract Certificate[] getServerCertificates()

返回作为定义会话一部分而建立的服务器证书链。

static void setDefaultHostnameVerifier(HostnameVerifier v)

设置由此类的新实例继承的默认 HostnameVerifier

static void setDefaultSSLSocketFactory(SSLSocketFactory sf)

设置 SSLSocketFactory的新实例继承的默认 SSLSocketFactory

void setHostnameVerifier(HostnameVerifier v)

为此实例设置 HostnameVerifier

void setSSLSocketFactory(SSLSocketFactory sf)

设置当此实例为安全https URL连接创建套接字时使用的 SSLSocketFactory

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

该对象的 hostnameVerifier

Protected constructors

HttpsURLConnection

Added in API level 1
HttpsURLConnection (URL url)

使用指定的URL创建一个 HttpsURLConnection

Parameters
url URL: the URL

Public methods

getCipherSuite

Added in API level 1
String getCipherSuite ()

返回此连接上使用的密码套件。

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 ()

获取由此类的新实例继承的默认 HostnameVerifier

Returns
HostnameVerifier the default host name verifier

也可以看看:

getDefaultSSLSocketFactory

Added in API level 1
SSLSocketFactory getDefaultSSLSocketFactory ()

获取由此类的新实例继承的默认静态 SSLSocketFactory

为安全的https URL连接创建套接字时使用套接字工厂。

Returns
SSLSocketFactory the default SSLSocketFactory

也可以看看:

getHostnameVerifier

Added in API level 1
HostnameVerifier getHostnameVerifier ()

在此实例上获取 HostnameVerifier

Returns
HostnameVerifier the host name verifier

也可以看看:

getLocalCertificates

Added in API level 1
Certificate[] getLocalCertificates ()

返回握手期间发送给服务器的证书。

注意:仅当使用基于证书的密码套件时,此方法才有用。

当多个证书可用于握手时,实现选择它认为可用的“最佳”证书链,并将其传递给另一方。 该方法允许调用者知道实际发送了哪个证书链。

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.

也可以看看:

getLocalPrincipal

Added in API level 1
Principal getLocalPrincipal ()

返回握手期间发送给服务器的主体。

注意:子类应该重写此方法。 如果未被覆盖,它将默认返回已发送到服务器的最终实体证书的X500Principal以获得基于证书的密码组,或者对于基于非证书的密码组(例如Kerberos)返回null。

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.

也可以看看:

getPeerPrincipal

Added in API level 1
Principal getPeerPrincipal ()

返回作为定义会话一部分而建立的服务器主体。

注意:子类应该重写此方法。 如果不重写,它将默认返回基于证书的密码组的服务器的最终实体证书的X500Principal,或者为基于非证书的密码组(例如Kerberos)引发SSLPeerUnverifiedException。

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.

也可以看看:

getSSLSocketFactory

Added in API level 1
SSLSocketFactory getSSLSocketFactory ()

在为安全https URL连接创建套接字时获取SSL套接字工厂。

Returns
SSLSocketFactory the SSLSocketFactory

也可以看看:

getServerCertificates

Added in API level 1
Certificate[] getServerCertificates ()

返回作为定义会话一部分而建立的服务器证书链。

注意:只有在使用基于证书的密码套件时才能使用此方法; 将它与非基于证书的密码套件(如Kerberos)一起使用时,将引发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.

也可以看看:

setDefaultHostnameVerifier

Added in API level 1
void setDefaultHostnameVerifier (HostnameVerifier v)

设置由此类的新实例继承的默认 HostnameVerifier

如果未调用此方法,则默认 HostnameVerifier假定不允许连接。

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")

也可以看看:

setDefaultSSLSocketFactory

Added in API level 1
void setDefaultSSLSocketFactory (SSLSocketFactory sf)

设置 SSLSocketFactory的新实例继承的默认 SSLSocketFactory

为安全的https URL连接创建套接字时使用套接字工厂。

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.

也可以看看:

setHostnameVerifier

Added in API level 1
void setHostnameVerifier (HostnameVerifier v)

为此实例设置 HostnameVerifier

此类的新实例继承由setDefaultHostnameVerifier设置的默认静态主机名验证程序。 调用此方法替换此对象的HostnameVerifier

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

也可以看看:

setSSLSocketFactory

Added in API level 1
void setSSLSocketFactory (SSLSocketFactory sf)

设置当此实例为安全https URL连接创建套接字时使用的 SSLSocketFactory

此类的新实例继承由SSLSocketFactory设置的默认静态setDefaultSSLSocketFactory 调用此方法替换此对象的SSLSocketFactory

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

也可以看看:

Hooray!