Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting chunked stream ended unexpectedly when I use HttpClient?
    primarykey
    data
    text
    <p>The problem only seems to occur with "large" files I'm trying to post.</p> <p>My code looks like this:</p> <pre><code>PostMethod method = new PostMethod(url); File input = new File(filePathname); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); method.setRequestEntity(entity); method.setRequestHeader("Content-Disposition", "attachment; filename=xyzzy") HttpClient client = new HttpClient(); Credentials defaultcreds = new UsernamePasswordCredentials("userid", "pw"); client.getState().setCredentials(new AuthScope("hostname", port, AuthScope.ANY_REALM), defaultcreds); try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new Exception("Method failed: " + method.getStatusLine()); } // Read the response body. byte[] responseBody = method.getResponseBody(); return new String(responseBody); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); throw e; } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); throw e; } finally { // Release the connection. method.releaseConnection(); } </code></pre> <p>The exception text looks like this:</p> <pre> Fatal transport error: chunked stream ended unexpectedly Exception in thread "main" java.io.IOException: chunked stream ended unexpectedly at org.apache.commons.httpclient.ChunkedInputStream.getChunkSizeFromInputStream(ChunkedInputStream.java:252) at org.apache.commons.httpclient.ChunkedInputStream.nextChunk(ChunkedInputStream.java:221) at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:176) at java.io.FilterInputStream.read(FilterInputStream.java:127) at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:108) at java.io.FilterInputStream.read(FilterInputStream.java:101) at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:127) at org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMethodBase.java:690) </pre> <p>I get a similar exception whether I use getResponseBody() or getResponseBodyAsStream().</p> <p>I shouldn't be getting much data back, but I am posting over 200mb of data.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload