public abstract class HttpsURLConnection extends HttpURLConnection
HttpsURLConnection扩展了HttpURLConnection ,支持https特定的功能。
有关https 规范的更多详细信息,请参阅http://www.w3.org/pub/WWW/Protocols/和RFC 2818。
本课程使用HostnameVerifier和SSLSocketFactory 。 为这两个类定义了默认实现。 但是,可以在每个类(静态)或每个实例的基础上替换这些实现。 所有新的HttpsURLConnection实例将在实例创建时分配“默认”静态值,但可以在connect之前调用适当的每个实例集方法来connect 。
| Modifier and Type | Field and Description |
|---|---|
protected HostnameVerifier |
hostnameVerifier
这个对象的
hostnameVerifier 。
|
chunkLength, fixedContentLength, fixedContentLengthLong, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessageallowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches| Modifier | Constructor and Description |
|---|---|
protected |
HttpsURLConnection(URL url)
创建一个
HttpsURLConnection使用指定的URL。
|
| Modifier and Type | Method and Description |
|---|---|
abstract String |
getCipherSuite()
返回此连接上正在使用的密码套件。
|
static HostnameVerifier |
getDefaultHostnameVerifier()
获取由此类的新实例继承的默认值
HostnameVerifier 。
|
static SSLSocketFactory |
getDefaultSSLSocketFactory()
获取由此类的新实例继承的默认静态
SSLSocketFactory 。
|
HostnameVerifier |
getHostnameVerifier()
获得这个实例上的
HostnameVerifier 。
|
abstract Certificate[] |
getLocalCertificates()
返回在握手期间发送到服务器的证书。
|
Principal |
getLocalPrincipal()
返回在握手期间发送到服务器的主体。
|
Principal |
getPeerPrincipal()
返回作为定义会话的一部分而建立的服务器的主体。
|
abstract Certificate[] |
getServerCertificates()
返回作为定义会话一部分而建立的服务器的证书链。
|
SSLSocketFactory |
getSSLSocketFactory()
获取为安全的https URL连接创建套接字时要使用的SSL套接字工厂。
|
static void |
setDefaultHostnameVerifier(HostnameVerifier v)
设置由此类的新实例继承的默认值
HostnameVerifier 。
|
static void |
setDefaultSSLSocketFactory(SSLSocketFactory sf)
设置由此类的新实例继承的默认值
SSLSocketFactory 。
|
void |
setHostnameVerifier(HostnameVerifier v)
设置此实例的
HostnameVerifier 。
|
void |
setSSLSocketFactory(SSLSocketFactory sf)
设置
SSLSocketFactory当此实例创建安全https URL连接插座使用。
|
disconnect, getErrorStream, getFollowRedirects, getHeaderField, getHeaderFieldDate, getHeaderFieldKey, getInstanceFollowRedirects, getPermission, getRequestMethod, getResponseCode, getResponseMessage, setChunkedStreamingMode, setFixedLengthStreamingMode, setFixedLengthStreamingMode, setFollowRedirects, setInstanceFollowRedirects, setRequestMethod, usingProxyaddRequestProperty, connect, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderFieldInt, getHeaderFieldLong, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toStringprotected HostnameVerifier hostnameVerifier
hostnameVerifier 。
protected HttpsURLConnection(URL url)
HttpsURLConnection使用指定的URL。
url - 网址
public abstract String getCipherSuite()
IllegalStateException - 如果在建立连接之前调用此方法。
public abstract Certificate[] getLocalCertificates()
注意:此方法仅在使用基于证书的密码套件时有用。
当多个证书可用于握手时,该实现将选择它认为“最佳”证书链可用,并将其传输到另一方。 该方法允许调用者知道实际发送了哪个证书链。
IllegalStateException - 如果在建立连接之前调用此方法。
getLocalPrincipal()
public abstract Certificate[] getServerCertificates() throws SSLPeerUnverifiedException
注意:此方法只能在使用基于证书的密码套件时使用; 与非基于证书的密码套件(如Kerberos)一起使用,将抛出SSLPeerUnverifiedException异常。
SSLPeerUnverifiedException - 如果对等体未被验证。
IllegalStateException - 如果在建立连接之前调用此方法。
getPeerPrincipal()
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException
注意:子类应该覆盖此方法。 如果没有被覆盖,它将默认返回服务器的最终实体证书的X500Principal,用于基于证书的密码体制,或为非基于证书的密码例如Kerberos引发SSLPeerUnverifiedException。
SSLPeerUnverifiedException - 如果对等体未被验证
IllegalStateException - 如果在建立连接之前调用此方法。
getServerCertificates() ,
getLocalPrincipal()
public Principal getLocalPrincipal()
注意:子类应该覆盖此方法。 如果没有被覆盖,它将默认返回发送到服务器的最终实体证书的X500Principal,用于基于证书的密码体制,或者返回非基于密码密码的密码,例如Kerberos。
IllegalStateException - 如果在建立连接之前调用此方法。
getLocalCertificates() ,
getPeerPrincipal()
public static void setDefaultHostnameVerifier(HostnameVerifier v)
HostnameVerifier 。
如果未调用此方法,则默认的HostnameVerifier假定不允许连接。
v - 默认主机名验证程序
IllegalArgumentException - 如果
HostnameVerifier参数为空。
SecurityException - 如果存在安全管理员,并且其
checkPermission方法不允许
SSLPermission("setHostnameVerifier")
getDefaultHostnameVerifier()
public static HostnameVerifier getDefaultHostnameVerifier()
HostnameVerifier 。
setDefaultHostnameVerifier(HostnameVerifier)
public void setHostnameVerifier(HostnameVerifier v)
HostnameVerifier 。
此类的新实例将继承由setDefaultHostnameVerifier设置的默认静态主机名验证器。 调用此方法替换此对象的HostnameVerifier 。
v - 主机名验证
IllegalArgumentException - 如果
HostnameVerifier参数为空。
getHostnameVerifier() ,
setDefaultHostnameVerifier(HostnameVerifier)
public HostnameVerifier getHostnameVerifier()
HostnameVerifier 。
public static void setDefaultSSLSocketFactory(SSLSocketFactory sf)
SSLSocketFactory 。
为安全的https URL连接创建套接字时使用套接字工厂。
sf - 默认的SSL套接字工厂
IllegalArgumentException - 如果SSLSocketFactory参数为空。
SecurityException - 如果安全管理器存在,并且其
checkSetFactory方法不允许指定套接字工厂。
getDefaultSSLSocketFactory()
public static SSLSocketFactory getDefaultSSLSocketFactory()
SSLSocketFactory 。
为安全的https URL连接创建套接字时使用套接字工厂。
SSLSocketFactory
setDefaultSSLSocketFactory(SSLSocketFactory)
public void setSSLSocketFactory(SSLSocketFactory sf)
SSLSocketFactory当此实例创建安全https URL连接插座使用。
此类的新实例将继承由SSLSocketFactory设置的默认静态SSLSocketFactory 。 调用此方法替换此对象的SSLSocketFactory 。
sf - SSL套接字工厂
IllegalArgumentException - 如果
SSLSocketFactory参数为空。
SecurityException - 如果存在安全管理员,并且其
checkSetFactory方法不允许指定套接字工厂。
getSSLSocketFactory()
public SSLSocketFactory getSSLSocketFactory()
SSLSocketFactory
setSSLSocketFactory(SSLSocketFactory)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.