質問

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top