I am trying to have a server (written in java) redirect to a HTTPS url (the url will never change) when accessed. If I compile the code with
java -Djavax.net.ssl.keyStore=mySrvKeystore -Djavax.net.ssl.keyStorePassword=password ProxyServer
and enter in the address, port, and localport as
https://google.com 443 5000
And try accessing
localhost:5000
on my machine, then I get the error
java.net.UnknownHostException: https://google.com
After debugging, I am pretty sure it breaks in this code block when I try to create the SSLSocket (secureServer).
SSLSocket secureServer;
try {
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
secureServer = (SSLSocket) factory.createSocket(host, port);
from_server = secureServer.getInputStream();
to_server = secureServer.getOutputStream();
}
The argument you pass as the host to factory.createSocket(host,port)
must not have the protocol prepended to it. It should simply be google.com
.
The reason is that Java is going to take that host
parameter and pass it as input to a DNS lookup. If you were to type host https://google.com
on the command line, you'd get a similar failure.
In here , it says this was a bug and resolved after some releases
In jdk 6 server, we get the same exception but in our jdk 8 server, no exception
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.