Name
HostnameVerifier
Synopsis
An
object that implements this interface may be used with an
HttpsURLConnection
object to handle the case in
which the hostname that appears in the URL does not match the
hostname obtained during the SSL handshake with the server. This
occurs, for example, when a website uses the secure certificate of
its parent web hosting company, for example. In this situation, the
verify( )
method of the HostnameVerifier
is called to
determine whether the connection should proceed or not.
verify( )
should return true
to
allow the connection to proceed, and should return
false
to cause the connection to fail. The
hostname
argument to verify(
)
specifies the hostname that appeared in the URL. The
session
argument specifies the
SSLSession
object that was established during the
handshake. Call getPeerHost(
)
on this object to determine the hostname reported during server
authentication. If no HostnameVerifier
is
registered with a HttpsURLConnection
object, and
no default verifier is registered with the
HttpsURLConnection
class, then hostname mismatches will always cause the connection to
fail. In user-driven applications such as web browsers, a
HostnameVerifier
can be used to ask the user
whether to proceed or not.
public interface HostnameVerifier { // Public Instance Methods boolean verify(String hostname, SSLSession session); }
Passed To
HttpsURLConnection.{setDefaultHostnameVerifier( )
,
setHostnameVerifier( )}
Returned By
HttpsURLConnection.{getDefaultHostnameVerifier( ...
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.