この問題は、投稿しようとしている「大きな」ファイルでのみ発生するようです。
私のコードは次のようになります。
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();
}
例外テキストは次のようになります。
致命的なトランスポート エラー: チャンク ストリームが予期せず終了しました スレッド「メイン」の例外 java.io.IOException: チャンク ストリームが予期せず終了しました org.apache.commons.httpclient.ChunkedInputStream.getChunkSizeFromInputStream(ChunkedInputStream.java:252) で org.apache.commons.httpclient.ChunkedInputStream.nextChunk(ChunkedInputStream.java:221) で org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:176) で java.io.FilterInputStream.read(FilterInputStream.java:127) で org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:108) で java.io.FilterInputStream.read(FilterInputStream.java:101) で org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:127) で org.apache.commons.httpclient.HttpMethodBase.getResponseBody (HttpMethodBase.java:690) で
getResponseBody() または getResponseBodyAsStream() のどちらを使用しても同様の例外が発生します。
あまり多くのデータが返ってこないはずですが、200 MB を超えるデータを投稿しています。