[英]HTTP connection to localhost fails
I have a Java application that makes REST requests to a Jetty server. 我有一个Java应用程序,可以向码头服务器发出REST请求。
It works if I connect to the server with a real DNS name but I get the following exception when I want to make requests to my local testing instance on localhost: 如果我使用真实的DNS名称连接到服务器,则可以使用,但是当我想向本地主机上的本地测试实例发出请求时,出现以下异常:
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
Requests in the browser and with my REST tool work. 浏览器中的请求以及与我的REST工具一起工作。
I got it to work when I use the IPv6 address for localhost: https://[0:0:0:0:0:0:0:1]/
当我为本地主机使用IPv6地址时,我可以使用它:
https://[0:0:0:0:0:0:0:1]/
It always worked for me with localhost. 它对localhost一直对我有用。 Is it possible that some Java or Windows 7 update changed a default setting so it uses IPv6 instead?
某些Java或Windows 7更新是否可能更改了默认设置,因此改用IPv6?
What can I do to make localhost work again and do I need to be worried that this might cause a problem on other PCs when they want to connect to our real server? 我该怎么办才能使localhost重新工作?我是否需要担心当其他PC要连接到我们的真实服务器时,这可能在其他PC上引起问题?
I would like to be IPv4 and IPv6 compatible. 我想兼容IPv4和IPv6。
edit: here is my hosts file (it is unedited) 编辑:这是我的主机文件(未经编辑)
# 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
So I finally found the problem. 所以我终于找到了问题。 Apparently Skype uses port 80 and 443 as alternative ports.
显然,Skype使用端口80和443作为备用端口。 As soon as I quit Skype everything worked.
我退出Skype后,一切都正常。
WebApp accessible via localhost but not 127.0.0.1 可通过localhost访问WebApp,但不能通过127.0.0.1访问
It probably worked with the IPv6 localhost address because Skype doesn't bind to that one. 它可能与IPv6本地主机地址一起使用,因为Skype不会绑定到该地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.