HTTPS 主机名错误:应为。这是什么原因造成的?
尝试使用 https 连接到服务器时,出现“HTTPS 主机名错误:”错误。我的网址看起来像这样,
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 <sub.domain.com>.
at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing
....
这是过去有效但不再有效的代码。系统架构发生了一些变化,但在联系负责人之前我需要获取更多数据。
什么可能导致此错误?我可以关闭 URLSpoofing 检查吗?
I am getting this 'HTTPS hostname wrong:' error when trying to connect to a server using https. My url looks something like this
https://sub.domain.com/tamnode/webapps/app/servlet.
I connect using the following code
// 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());
but then get an error
IOException: HTTPS hostname wrong: should be <sub.domain.com>.
at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing
....
This is code which has worked in the past but no longer. There have been some changes to the system architecture but I need to get more data before approaching those responsible.
What can cause this error? Can I turn off the URLSpoofing check?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
看起来domain.com 的SSL 证书已被授予sub.domain.com。或者,更有可能的是,domain.com 已重命名为 sub.domain.com,而没有更新 SSL 证书。
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 关于可能原因的说法是正确的。
还有一种方法可以关闭欺骗检查。
您可以创建一个实现 HostnameVerifier 的对象 在比“通常”更多的情况下返回 true。
您可以通过调用 setHostnameVerifier 问题代码中的连接对象。
这个答案的“灵感来自”:http://www.java-samples。 com/showtutorial.php?tutorialid=211
我发现该查询的链接:http://www.google.com/search?q=https+hostname+wrong+should+be
还有一点要注意:在执行此操作之前请三思。您将在客户端和服务器组件之间的安全性中造成可利用的弱点。
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.
我收到此异常 -
java.io.IOException: HTTPS 主机名错误:应该是
。我的解决方案是更改我的自签名证书并设置
CN=localhost
。或者
将您的证书域名
cn=
添加到可能位于 c:/windows/system32/drivers/etc/... 的主机文件中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/...以下代码解决了我的问题
The following code resolved my problem
默认情况下,Java 会验证证书 CN(通用名称)是否与 URL 中的主机名相同。如果证书中的 CN 与主机名不同,您的 Web 服务客户端将失败并出现以下异常: java.io.IOException: HTTPS 主机名错误:应该是证书中的主机名。
Java by default verifies that the certificate CN (Common Name) is the same as hostname in the URL. If the CN in the certificate is not the same as the host name, your web service client fails with the following exception: java.io.IOException: HTTPS hostname wrong: should be hostname as in the certificates.
这只是“svarog”帖子的替代品
This is just an alternative of 'svarog' post
使用主机名(dns 名称)作为别名。
前任:
Use host name (dns name) as Alias name.
Ex: