HTTPS hostname wrong: should be <sub.domain.com>. What causes this?
I got this exception - java.io.IOException: HTTPS hostname wrong: should be <localhost>
.
My solution is I changed my self-signed certificate and make the CN=localhost
.
OR
Add your certificate domain-name cn=<domain-name>
to your host file probably located at c:/windows/system32/drivers/etc/...
It looks like the SSL certificate for domain.com has been given to sub.domain.com. Or, more likely, what was domain.com has been renamed to sub.domain.com without updating the SSL certificate.
cletus is right about the probable cause.
There is a way to turn off the spoof checking, too.
You can create an object that implements HostnameVerifier that returns true under more circumstances than 'usual'.
You would replace the default HostnameVerifier by calling setHostnameVerifier on the connection object in the code in the question.
This answer was 'inspired by': http://www.java-samples.com/showtutorial.php?tutorialid=211
I found that link with this query: http://www.google.com/search?q=https+hostname+wrong+should+be
One more note: think twice before you do this. You will create an exploitable weakness in the security between your client and server components.