You can connect httpsbased url java djava javasec urlclient https always
Chapter 14. SSL and HTTPS 287
As an example, here's a simple URL−based client that can retrieve arbitrary URLs:
piccolo% java javasec.samples.ch14.URLClient http://www.sun.com/ ... lots of output from sun.com ...
Similarly, by specifying the appropriate property for the HTTPS protocol handler, you can connect to an HTTPS−based URL:
There are times when this verification is insufficient. If you
connect to https://192.18.297.41/, the default verification
will fail. The certificate presented by that site has an embedded name
of www.sun.com, and even though 192.18.297.41 is the correct IP
address, the protocol handler will do a string comparison of
192.18.297.41 and www.sun.com and will fail. In cases such as
this you may want to look up the IP address of the name in the
certificate and see if it matches your target. You may also want to ask
the user if it's okay to proceed (regardless of whether the names
match).
To handle such situations, you can implement a hostname verifier in order to perform extended hostname verification. Extended hostname verification is used only if the name in the certificate and the hostname in the URL don't match; if the names match, the HTTPS protocol handler does not call the hostname verifier. Hence, a hostname verifier cannot be used to prevent any arbitrary connection.
There are two methods by which you can install a hostname verifier:
public static void setDefaultHostnameVerifier(HostnameVerifier
v)
Set the hostname verifier that will be used by default for all future
instances of HTTPS connections.
import com.sun.net.ssl.*;
public class HttpsClient {