- java.lang.Object
-
- java.net.URLConnection
-
- java.net.HttpURLConnection
-
- javax.net.ssl.HttpsURLConnection
-
public abstract class HttpsURLConnection extends HttpURLConnection
HttpsURLConnection
extendsHttpURLConnection
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
andSSLSocketFactory
. There are default implementations defined for both classes. However, the implementations can be replaced on a per-class (static) or per-instance basis. All newHttpsURLConnection
s 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) beforeconnect
ing.- Since:
- 1.4
-
-
Field Summary
Fields Modifier and Type Field and Description protected HostnameVerifier
hostnameVerifier
ThehostnameVerifier
for this object.-
Fields inherited from class java.net.HttpURLConnection
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, responseMessage
-
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
-
-
Constructor Summary
Constructors Modifier Constructor and Description protected
HttpsURLConnection(URL url)
Creates anHttpsURLConnection
using the URL specified.
-
Method Summary
Methods Modifier and Type Method and Description abstract String
getCipherSuite()
Returns the cipher suite in use on this connection.static HostnameVerifier
getDefaultHostnameVerifier()
Gets the defaultHostnameVerifier
that is inherited by new instances of this class.static SSLSocketFactory
getDefaultSSLSocketFactory()
Gets the default staticSSLSocketFactory
that is inherited by new instances of this class.HostnameVerifier
getHostnameVerifier()
Gets theHostnameVerifier
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.abstract Certificate[]
getServerCertificates()
Returns the server's certificate chain 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.static void
setDefaultHostnameVerifier(HostnameVerifier v)
Sets the defaultHostnameVerifier
inherited by a new instance of this class.static void
setDefaultSSLSocketFactory(SSLSocketFactory sf)
Sets the defaultSSLSocketFactory
inherited by new instances of this class.void
setHostnameVerifier(HostnameVerifier v)
Sets theHostnameVerifier
for this instance.void
setSSLSocketFactory(SSLSocketFactory sf)
Sets theSSLSocketFactory
to be used when this instance creates sockets for secure https URL connections.-
Methods inherited from class java.net.HttpURLConnection
disconnect, getErrorStream, getFollowRedirects, getHeaderField, getHeaderFieldDate, getHeaderFieldKey, getInstanceFollowRedirects, getPermission, getRequestMethod, getResponseCode, getResponseMessage, setChunkedStreamingMode, setFixedLengthStreamingMode, setFixedLengthStreamingMode, setFollowRedirects, setInstanceFollowRedirects, setRequestMethod, usingProxy
-
Methods inherited from class java.net.URLConnection
addRequestProperty, 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, toString
-
-
-
-
Field Detail
-
hostnameVerifier
protected HostnameVerifier hostnameVerifier
ThehostnameVerifier
for this object.
-
-
Constructor Detail
-
HttpsURLConnection
protected HttpsURLConnection(URL url)
Creates anHttpsURLConnection
using the URL specified.- Parameters:
url
- the URL
-
-
Method Detail
-
getCipherSuite
public abstract String getCipherSuite()
Returns the cipher suite in use on this connection.- Returns:
- the cipher suite
- Throws:
IllegalStateException
- if this method is called before the connection has been established.
-
getLocalCertificates
public abstract 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:
- 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()
-
getServerCertificates
public abstract Certificate[] getServerCertificates() throws SSLPeerUnverifiedException
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:
- 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:
getPeerPrincipal()
-
getPeerPrincipal
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException
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:
- 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 verifiedIllegalStateException
- if this method is called before the connection has been established.- Since:
- 1.5
- See Also:
getServerCertificates()
,getLocalPrincipal()
-
getLocalPrincipal
public 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:
- 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.- Since:
- 1.5
- See Also:
getLocalCertificates()
,getPeerPrincipal()
-
setDefaultHostnameVerifier
public static void setDefaultHostnameVerifier(HostnameVerifier v)
Sets the defaultHostnameVerifier
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
- the default host name verifier- Throws:
IllegalArgumentException
- if theHostnameVerifier
parameter is null.SecurityException
- if a security manager exists and itscheckPermission
method does not allowSSLPermission("setHostnameVerifier")
- See Also:
getDefaultHostnameVerifier()
-
getDefaultHostnameVerifier
public static HostnameVerifier getDefaultHostnameVerifier()
Gets the defaultHostnameVerifier
that is inherited by new instances of this class.- Returns:
- the default host name verifier
- See Also:
setDefaultHostnameVerifier(HostnameVerifier)
-
setHostnameVerifier
public void setHostnameVerifier(HostnameVerifier v)
Sets theHostnameVerifier
for this instance.New instances of this class inherit the default static hostname verifier set by
setDefaultHostnameVerifier
. Calls to this method replace this object'sHostnameVerifier
.- Parameters:
v
- the host name verifier- Throws:
IllegalArgumentException
- if theHostnameVerifier
parameter is null.- See Also:
getHostnameVerifier()
,setDefaultHostnameVerifier(HostnameVerifier)
-
getHostnameVerifier
public HostnameVerifier getHostnameVerifier()
Gets theHostnameVerifier
in place on this instance.- Returns:
- the host name verifier
- See Also:
setHostnameVerifier(HostnameVerifier)
,setDefaultHostnameVerifier(HostnameVerifier)
-
setDefaultSSLSocketFactory
public static void setDefaultSSLSocketFactory(SSLSocketFactory sf)
Sets the defaultSSLSocketFactory
inherited by new instances of this class.The socket factories are used when creating sockets for secure https URL connections.
- Parameters:
sf
- the default SSL socket factory- Throws:
IllegalArgumentException
- if the SSLSocketFactory parameter is null.SecurityException
- if a security manager exists and itscheckSetFactory
method does not allow a socket factory to be specified.- See Also:
getDefaultSSLSocketFactory()
-
getDefaultSSLSocketFactory
public static SSLSocketFactory getDefaultSSLSocketFactory()
Gets the default staticSSLSocketFactory
that is inherited by new instances of this class.The socket factories are used when creating sockets for secure https URL connections.
- Returns:
- the default
SSLSocketFactory
- See Also:
setDefaultSSLSocketFactory(SSLSocketFactory)
-
setSSLSocketFactory
public void setSSLSocketFactory(SSLSocketFactory sf)
Sets theSSLSocketFactory
to be used when this instance creates sockets for secure https URL connections.New instances of this class inherit the default static
SSLSocketFactory
set bysetDefaultSSLSocketFactory
. Calls to this method replace this object'sSSLSocketFactory
.- Parameters:
sf
- the SSL socket factory- Throws:
IllegalArgumentException
- if theSSLSocketFactory
parameter is null.- See Also:
getSSLSocketFactory()
-
getSSLSocketFactory
public SSLSocketFactory getSSLSocketFactory()
Gets the SSL socket factory to be used when creating sockets for secure https URL connections.- Returns:
- the
SSLSocketFactory
- See Also:
setSSLSocketFactory(SSLSocketFactory)
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/net/ssl/httpsurlconnection.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.