Joakim Erdfelt joakim.erdfelt at gmail.com
Tue May 15 11:38:56 UTC 2018


You're server is reporting the wrong Content-Length.

"<html><body><h1>Heading</h1><p>Some Text</p></body></html>" is 59
characters

But the server said "Content-Length: 58"

Also, "Connection: keep-alive" is a HTTP/1.0 concept only, but is being
reported on your HTTP/1.1 request/response improperly.


On Mon, May 14, 2018 at 7:20 PM, Simon Roberts <
simon at dancingcloudservices.com> wrote:

>
> I have a very simple attempt to use the Java 10 / incubator httpclient
> api. It works on "regular" resources, but fails horribly when attempting to
> get things from localhost. It fails using 127.0.0.1, the actual
> non-loopback IP, and the name localhost. The server is running, and
> presenting a very simple web page (I originally tried json, but have since
> simplified it attempting to find out what's amiss).
>
> The code is as simple as I can imagine (and that might be the problem :)
>
> --------------------------------------------------------------
>     HttpClient client = HttpClient.newHttpClient();
>     URI uri = URI.create("http://192.168.1.102:8080/index.html");
>
>     HttpRequest getRequest = HttpRequest.newBuilder()
>         .uri(uri).GET().build();
>
>     HttpResponse<String> response = client.send(getRequest,
>         HttpResponse.BodyHandler.asString());
>     System.out.println("response to get: " + response.body());
> --------------------------------------------------------------
>
> The error prints a long stack trace, which I suppose I must post in its
> entiretly:
>
> --------------------------------------------------------------
>
> 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)
>
> Process finished with exit code 1
> --------------------------------------------------------------
>
> If I use a curl to make the request of my (node/express) server, I get:
>
> --------------------------------------------------------------
> $ curl -v http://localhost:8080/index.html
> *   Trying 127.0.0.1...
> * Connected to localhost (127.0.0.1) port 8080 (#0)
> > GET /index.html HTTP/1.1
> > Host: localhost:8080
> > User-Agent: curl/7.47.0
> > Accept: */*
> >
> < HTTP/1.1 200 OK
> < X-Powered-By: Express
> < Content-Type: text/html; charset=utf-8
> < Content-Length: 58
> < ETag: W/"3a-EwoPOQKsJivlqZA3z/ulngzMv9U"
> < Date: Tue, 15 May 2018 00:18:47 GMT
> < Connection: keep-alive
> <
> * Connection #0 to host localhost left intact
> <html><body><h1>Heading</h1><p>Some Text</p></body></html>
> --------------------------------------------------------------
>
> Anyone able to tell me what I'm doing wrong?
>
> TIA!
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20180515/60bae1ba/attachment.html>


More information about the net-dev mailing list