当我将数据发布到API的终端并获得响应时,由于com.sun.jersey.api.client.ClientHandlerException
,我面临异常java.io.IOException: Premature EOF
:
response = client.resource(this.url)
.type(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON_TYPE)
.header("Accept", "application/json")
.post(ClientResponse.class, payloadToBeRequested);
JSONObject responseObj = new JSONObject(response.getEntity(String.class));
该异常的确切堆栈跟踪指向调用方法getEntity
的行:
com.sun.jersey.api.client.ClientHandlerException: java.io.IOException: Premature EOF
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:563)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:506)
at BlockstemRequester.lambda$run$0(BlockstemRequester.java:51)
at java.lang.Iterable.forEach(Iterable.java:75)
at java.util.Collections$SynchronizedCollection.forEach(Collections.java:2062)
at BlockstemRequester.run(BlockstemRequester.java:29)
Caused by: java.io.IOException: Premature EOF
at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:565)
at sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:609)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:696)
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3335)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.Reader.read(Reader.java:140)
at com.sun.jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.java:171)
at com.sun.jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.java:157)
at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.readFromAsString(AbstractMessageReaderWriterProvider.java:114)
at com.sun.jersey.core.impl.provider.entity.StringProvider.readFrom(StringProvider.java:73)
at com.sun.jersey.core.impl.provider.entity.StringProvider.readFrom(StringProvider.java:58)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:553)
... 5 more
我已经尝试了一些解决方案来解读一些问题,但我对此一无所知。那么,从POST请求中获取实体时,可能会出现什么问题可能会导致此Premature EOF
?
谢谢。