与localhost的HTTP连接失败

时间:2013-01-17 08:50:00

标签: java rest jersey jetty ipv6

我有一个Java应用程序向Jetty服务器发出REST请求。

如果我使用真实的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:https://[0:0:0:0:0:0:0:1]/

的IPv6地址时,我得到了它的工作

它总是对我有localhost。某些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

1 个答案:

答案 0 :(得分:1)

所以我终于找到了问题。显然,Skype使用端口80和443作为备用端口。 一旦我退出Skype一切正常。

WebApp accessible via localhost but not 127.0.0.1

它可能与IPv6本地主机地址一起使用,因为Skype不绑定那个地址。