我正在使用jersey api客户端来调用基于REST的webservice(此服务托管在我的localhost中)。当我打电话
String entity = (client response object here).getEntity(String.class);
我得到以下异常:
Caused by: java.io.IOException: Premature EOF
at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:565) ~[?:1.7.0_71]
at sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:609) ~[?:1.7.0_71]
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:696) ~[?:1.7.0_71]
at java.io.FilterInputStream.read(FilterInputStream.java:133) ~[?:1.7.0_71]
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3053) ~[?:1.7.0_71]
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283) ~[?:1.7.0_71]
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325) ~[?:1.7.0_71]
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177) ~[?:1.7.0_71]
at java.io.InputStreamReader.read(InputStreamReader.java:184) ~[?:1.7.0_71]
at java.io.Reader.read(Reader.java:140) ~[?:1.7.0_71]
at com.sun.jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.java:171) ~[jersey-core-1.17.jar:1.17]
at com.sun.jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.java:157) ~[jersey-core-1.17.jar:1.17]
at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.readFromAsString(AbstractMessageReaderWriterProvider.java:114) ~[jersey-core-1.17.jar:1.17]
at com.sun.jersey.core.impl.provider.entity.StringProvider.readFrom(StringProvider.java:73) ~[jersey-core-1.17.jar:1.17]
at com.sun.jersey.core.impl.provider.entity.StringProvider.readFrom(StringProvider.java:58) ~[jersey-core-1.17.jar:1.17]
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:565) ~[jersey-client-1.17.jar:1.17]
... 59 more
我知道我的webserive正在给我200 OK
回复。查看从基于REST的webserive获得的json响应:
{"user_likes":[],"status_code":200,"status_msg":"OK"}
Here is the response of my webservie:-
* Adding handle: conn: 0x7fee13808c00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fee13808c00) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /social/69124/likes/?comic_uuids=ccd48dca-955f-4ad4-838e-aa558b86679d,ff201290-1f92-4b13-bf11-20b61500a9aa,f1e77de0-0c75-4f0c-8515-7fa90e9a6baa,11e19c81-9e74-4a96-a34f-9696c3ab4a4e,152a624e-e06b-47ed-83bc-75ce26ce4a13,e9f0e9d6-5e35-4012-a7a9-6c37d5781205,7c718479-d8ed-4b67-9584-1647c34c08f2,4febbdde-8ab7-4127-b178-6c91f58deab5,ad583bc5-17d6-4982-9412-26fadfb8e261,1a53e323-5577-49a3-8151-a39a75084636 HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:8080
> Accept: */*
>
HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< Access-Control-Allow-Origin: *
< Content-Type: application/json;charset=utf-8
< Transfer-Encoding: chunked
< Date: Wed, 13 Apr 2016 10:28:51 GMT
<
* transfer closed with outstanding read data remaining
* Closing connection 0
curl: (18) transfer closed with outstanding read data remaining
{"user_likes":[],"status_code":200,"status_msg":"OK"}
请帮助我。
答案 0 :(得分:1)
从您的服务器回答显然是Content-Length
标题响应的问题。它不包含Content-Length
标头。您应该将其添加到具有正确值的响应中。