gpt4 book ai didi

java - 与本地主机的 HTTP 连接失败

转载 作者:行者123 更新时间:2023-11-30 11:36:49 24 4
gpt4 key购买 nike

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

如果我使用真实的 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

浏览器中的请求和我的 REST 工具工作。

当我为本地主机使用 IPv6 地址时,它开始工作:https://[0:0:0:0:0:0:0:1]/

它对我来说总是适用于 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

最佳答案

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

WebApp accessible via localhost but not 127.0.0.1

它可能适用于 IPv6 本地主机地址,因为 Skype 未绑定(bind)到该地址。

关于java - 与本地主机的 HTTP 连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14375191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com