作者:冬-冰释_488 | 来源:互联网 | 2022-12-17 13:50
我一直在试验Java 9/10孵化器中的HttpClient东西,并且有以下简单的代码(几乎从项目主页上被盗!):
URI uri = URI.create("http://192.168.1.102:8080/");
HttpRequest getRequest = HttpRequest.newBuilder()
.uri(uri)
.GET()
.build();
HttpResponse respOnse= client.send(getRequest,
HttpResponse.BodyHandler.asString());
System.out.println("response to get: " + response.body());
如果它指向不是localhost的URL,我发现它工作正常,但如果我要求localhost(无论是名称为"localhost",172.0.0.1,还是本地主机的实际IP地址),它都会失败.错误很奇怪,整个堆栈跟踪都没有提到我的任何代码.
WARNING: Using incubator modules: jdk.incubator.httpclient
Exception in thread "main" java.io.EOFException: EOF reached while reading
at jdk.incubator.httpclient/jdk.incubator.http.Http1AsyncReceiver$Http1TubeSubscriber.onComplete(Http1AsyncReceiver.java:507)
at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$ReadSubscription.signalCompletion(SocketTube.java:551)
at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$InternalReadSubscription.read(SocketTube.java:728)
at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$SocketFlowTask.run(SocketTube.java:171)
at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198)
at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:271)
at jdk.incubator.httpclient/jdk.incubator.http.internal.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:224)
at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$InternalReadSubscription.signalReadable(SocketTube.java:675)
at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$InternalReadPublisher$ReadEvent.signalEvent(SocketTube.java:829)
at jdk.incubator.httpclient/jdk.incubator.http.SocketTube$SocketFlowEvent.handle(SocketTube.java:243)
at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:769)
at jdk.incubator.httpclient/jdk.incubator.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:731)
有一个本地运行的服务器,我可以使用Web浏览器的简单请求连接到它.
有什么想法吗?
[编辑]我发现,我相信,这个项目的邮件列表.它被"混淆了"(它完全欺骗了我!)但显示为:net dash dev at openjdk dot java dot net
我也会在那里发布,看看他们是否有任何输入.
[编辑2]我很确定这与localhost(每个原始标题)无关,但是与node.js/express协议协商(这是我正在使用的服务器因为它很容易实验) ).偶尔节点(例如,使用非LF终止的最后一行文本)似乎报告错误的内容长度,但这不是问题,因为失败仍然以正确的长度发生.我认为这可能是尝试将连接升级到HTTP/2.0的一个错误,但还不知道......
[编辑3]在浪费了太多的生命实验之后,我很确定node.js 8.11.1(以及表达4.13.4和body-parser 1.15.1)处理升级请求的方式a到导致问题的HTTP 2.0.但我不知道是什么.我放弃了,并将继续使用不同服务器的httpClient学习过程.