【发布时间】:2010-12-20 14:21:08
【问题描述】:
我在尝试使用 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 检查吗?
【问题讨论】: