R
Ray Thomas
I'm trying to use the apache commons httpclient package to send a
request to an application running on an IIS 5 server. The response
returned from the server contains the "Transfer-encoding: chunked"
header but does not seem to be sending the proper chunk size
information in the response body. The ChunkedInputStream chokes on
the response data and throws an exception that appears to result from
an attempt to parse a chunk size out of part of the actual page data:
------------------------------------------------------------------------
java.io.IOException: Bad chunk size: <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 3.2 Final//EN">
at org.apache.commons.httpclient.ChunkedInputStream.getChunkSizeFromInputStream(ChunkedInputStream.java:320)
at org.apache.commons.httpclient.ChunkedInputStream.nextChunk(ChunkedInputStream.java:237)
at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:192)
at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:212)
------------------------------------------------------------------------
The code I'm using (fairly simple stuff but in case I'm missing
something...):
String xferEncHeader = getHeader("Transfer-Encoding");
boolean usesChunkedTransferEncoding = "chunked".equals(xferEncHeader);
if (usesChunkedTransferEncoding) {
InputStream chunkedResponseData = new
ChunkedInputStream(httpMethod.getResponseBodyAsStream(),
httpMethod);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] xferbuf = new byte[1024];
int xferbytes = -1;
while ((xferbytes = chunkedResponseData.read(xferbuf)) != -1) {
buffer.write(xferbuf, 0, xferbytes);
}
buffer.flush();
String localResponseBodyCache = buffer.toByteArray();
}
Any ideas what's wrong? Is it a bug in
commons.httpclient.ChunkedInputStream? Does anyone know a way to work
around it?
request to an application running on an IIS 5 server. The response
returned from the server contains the "Transfer-encoding: chunked"
header but does not seem to be sending the proper chunk size
information in the response body. The ChunkedInputStream chokes on
the response data and throws an exception that appears to result from
an attempt to parse a chunk size out of part of the actual page data:
------------------------------------------------------------------------
java.io.IOException: Bad chunk size: <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 3.2 Final//EN">
at org.apache.commons.httpclient.ChunkedInputStream.getChunkSizeFromInputStream(ChunkedInputStream.java:320)
at org.apache.commons.httpclient.ChunkedInputStream.nextChunk(ChunkedInputStream.java:237)
at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:192)
at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:212)
------------------------------------------------------------------------
The code I'm using (fairly simple stuff but in case I'm missing
something...):
String xferEncHeader = getHeader("Transfer-Encoding");
boolean usesChunkedTransferEncoding = "chunked".equals(xferEncHeader);
if (usesChunkedTransferEncoding) {
InputStream chunkedResponseData = new
ChunkedInputStream(httpMethod.getResponseBodyAsStream(),
httpMethod);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] xferbuf = new byte[1024];
int xferbytes = -1;
while ((xferbytes = chunkedResponseData.read(xferbuf)) != -1) {
buffer.write(xferbuf, 0, xferbytes);
}
buffer.flush();
String localResponseBodyCache = buffer.toByteArray();
}
Any ideas what's wrong? Is it a bug in
commons.httpclient.ChunkedInputStream? Does anyone know a way to work
around it?