我有一个向 Jetty 服务器发出 REST 请求的 Java 应用程序。
如果我使用真实的 DNS 名称连接到服务器,它可以工作,但是当我想向 localhost 上的本地测试实例发出请求时出现以下异常:
Caused by: com.sun.jersey.api.client.ClientHandlerException: java.io.IOException: Stream closed
at com.sun.jersey.api.client.ClientResponse.hasEntity(ClientResponse.java:480) ~[jersey-client-1.14.jar:1.14]
at com.sun.jersey.client.apache.ApacheHttpClientHandler.handle(ApacheHttpClientHandler.java:182) ~[jersey-apache-client-1.14.jar:1.14]
... 12 common frames omitted
Caused by: java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:162) ~[na:1.7.0_05]
at java.io.BufferedInputStream.reset(BufferedInputStream.java:435) ~[na:1.7.0_05]
at java.io.FilterInputStream.reset(FilterInputStream.java:226) ~[na:1.7.0_05]
at java.io.FilterInputStream.reset(FilterInputStream.java:226) ~[na:1.7.0_05]
at com.sun.jersey.api.client.ClientResponse.hasEntity(ClientResponse.java:464) ~[jersey-client-1.14.jar:1.14]
... 13 common frames omitted
浏览器中的请求和我的 REST 工具工作。
当我使用 localhost 的 IPv6 地址时,我让它工作了:https://[0:0:0:0:0:0:0:1]/
它总是适用于本地主机。是否有可能某些 Java 或 Windows 7 更新更改了默认设置,因此改为使用 IPv6?
我该怎么做才能使 localhost 再次工作,我是否需要担心当其他 PC 想要连接到我们的真实服务器时这可能会导致问题?
我想兼容 IPv4 和 IPv6。
编辑:这是我的主机文件(未编辑)
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost