HTTPS主机名错误:应为。 是什么导致这个?

尝试使用https连接到服务器时,我收到此’HTTPS hostname wrong:’错误。 我的url看起来像这样

https://sub.domain.com/tamnode/webapps/app/servlet. 

我使用以下代码连接

  // Create a URLConnection object for a URL URL url = new URL(requestedURL); HttpURLConnection.setFollowRedirects(false); // connect connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("User-Agent", USER_AGENT); //$NON-NLS-1$ OutputStreamWriter wr = new OutputStreamWriter(connection .getOutputStream()); 

但后来得到一个错误

 IOException: HTTPS hostname wrong: should be . at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing .... 

这是过去曾经工作但不再有效的代码。 系统架构已经发生了一些变化,但我需要在接近负责人之前获得更多数据。

什么可能导致此错误? 我可以关闭URLSpoofing检查吗?

看起来domain.com的SSL证书已经提供给sub.domain.com。 或者,更有可能的是,在没有更新SSL证书的情况下,domain.com已被重命名为sub.domain.com。

克莱图斯对可能的原因是正确的。

还有一种方法可以关闭欺骗检查。

您可以创建一个实现HostnameVerifier的对象,该对象在比“通常”更多的情况下返回true。

您可以通过在问题代码中的连接对象上调用setHostnameVerifier来替换默认的HostnameVerifier。

这个答案是“受到启发”: http : //www.java-samples.com/showtutorial.php?tutorials = 211

我发现该链接与此查询相关联: http : //www.google.com/search? q = https + hostname+wrong+should+be

还有一点需要注意:在你这样做之前要三思。 您将在客户端和服务器组件之间的安全性中创建可利用的弱点。

我遇到了这个exception – java.io.IOException: HTTPS hostname wrong: should be

我的解决方案是我更改了自签名证书并使CN=localhost

要么

将证书域名cn=到主机文件中,该文件可能位于c:/ windows / system32 / drivers / etc / …

这解决了我的问题

  static { //for localhost testing only javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier( new javax.net.ssl.HostnameVerifier(){ @Override public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { if (hostname.equals("your_domain")) { return true; } return false; } }); }