简体   繁体   English

与本地主机的HTTP连接失败

[英]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.

相关问题 与HTTP服务的连接失败 - Connection to a HTTP service fails 如果身份验证失败,请关闭 HTTP 连接 - Close HTTP connection if authentication fails org.apache.http.conn.HttpHostConnectException:拒绝连接到http:// localhost - org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused 即使连接处于活动状态,HTTP 请求也会失败 - HTTP request fails even if the connection is active 无法执行 HTTP 请求:连接到 localhost:8000 [localhost/127.0.0.1] 失败:连接被拒绝(连接被拒绝) - Unable to execute HTTP request: Connect to localhost:8000 [localhost/127.0.0.1] failed: Connection refused (Connection refused) 与EJB的远程连接在本地主机上运行,​​但在127.0.0.1和另一台服务器上失败 - Remote Connection to EJB working on localhost but fails on 127.0.0.1 and another server EC2到RDS的连接失败,但本地主机到RDS的工作正常 - EC2 to RDS connection fails but localhost to RDS works Spring Rest Template Client:拒绝连接到http:// localhost:8080 - Spring Rest Template Client : Connection to http://localhost:8080 refused 用Java进行的HTTP连接失败,重定向过多? - HTTP connection made in Java fails with too many redirects? Keycloak Testcontainer 因等待 URL 可访问而超时(http://localhost:55127/auth 应返回 HTTP 200) - Keycloak Testcontainer fails due Timed out waiting for URL to be accessible (http://localhost:55127/auth should return HTTP 200)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM