Announcement

Collapse
No announcement yet.

Http sender failed to parse http Entity into string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Http sender failed to parse http Entity into string

    I got a `IoException` When I try to parse http Entity from a ASP.NET api into string.

    Code:
      String responseBody = IOUtils.toString(httpResponse.getEntity().getContent(), responseCharset)
    or
    Code:
    String responseBody =EntityUtils.toString((httpResponse.getEntity());

    I try to do it by using these two method.They all works fine except the **ASP.NET api**,which can be requested normally with Postman.

    I got the function which throw the exception when run at 'while' the second time.


    Code:
     public static long copyLarge(InputStream input, OutputStream output, byte[] buffer)  throws IOException {
                long count = 0;
                int n = 0;
                while (EOF != (n = input.read(buffer))) {
                    output.write(buffer, 0, n);
                    count += n;
                }
                return count;
            }
    The stack as follows:

    > Premature end of chunk coded message body: closing chunk expected at
    > org.apache.http.impl.io.ChunkedInputStream.getChun kSize(ChunkedInputStream.java:268)
    > at
    > org.apache.http.impl.io.ChunkedInputStream.nextChu nk(ChunkedInputStream.java:227)
    > at
    > org.apache.http.impl.io.ChunkedInputStream.read(Ch unkedInputStream.java:186)
    > at
    > org.apache.http.conn.EofSensorInputStream.read(Eof SensorInputStream.java:137)
    > at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.j ava:284) at
    > sun.nio.cs.StreamDecoder.implRead(StreamDecoder.ja va:326) at
    > sun.nio.cs.StreamDecoder.read(StreamDecoder.java:1 78) at
    > java.io.InputStreamReader.read(InputStreamReader.j ava:184) at
    > java.io.Reader.read(Reader.java:140) at
    > org.apache.commons.io.IOUtils.copyLarge(IOUtils.ja va:1928) at
    > org.apache.commons.io.IOUtils.copyLarge(IOUtils.ja va:1907) at
    > org.apache.commons.io.IOUtils.copy(IOUtils.java:18 84) at
    > org.apache.commons.io.IOUtils.copy(IOUtils.java:18 34) at
    > org.apache.commons.io.IOUtils.toString(IOUtils.jav a:705)


    **The second way also failed when try to read buffer from a EofSensorInputStream**

    version:3.4.2 jdk:1.8.0_65

    Thanks in advance!
Working...
X