The issue seems to be that when the servlet grabs Content-Length header, it gets -1 and the folks who wrote the servlet use that for a new byte[Content-Length]. So with content-length = -1 httpclient will automatically use Chunked coding? I manually set it via API anyways. With chunked=true, should the servlet have a content length? How SHOULD the servlet be determining how many bytes to read or when to end reading?

-------- Original Message --------
Subject: Re: HTTP Post without content-length : server failure even when
chunked
From: Oleg Kalnichevski <[email protected]>
To: HttpClient User Discussion <[email protected]>
Date: 04/26/2010 04:51 PM

On Mon, 2010-04-26 at 15:22 -0500, hanasaki jiji wrote:
Using httpclient 4.0.1 and doing an http POST NOTE: this has been
tried with both "chunked = true" and false

The POST code does the following: InputStreamEntity
uploadHttpEntity = new InputStreamEntity(sourceInputStream, -1);
uploadHttpEntity.setChunked(true);
httppost.setEntity(uploadHttpEntity);

Where the InputStream is of an unknown source.  It could be the
result of ByteArrayInputStream, from a file or any other class that
resolves to an "InputStream".  Thus, the "-1" in the
InputStreamEntity and the use of this class vs perhaps a
StringEntity.

The server code explicitly looks for the Content-Length header
which is seen as -1 and thus fails thinking that the length is
either -1 or it already has an EOF.

Setting entity's length to -1 will NOT cause HttpClient to send -1
in the Content-Length header. HttpClient will automatically use
chunk coding if the content length is unknown (negative).

Oleg

Interestingly a POST with java.net....HTTPURLConnection works
fine.

How can HTTPClient be used and have it send up the length as the
java.net classes do?

Thank you,

---------------------------------------------------------------------


To unsubscribe, e-mail: [email protected]
For additional commands, e-mail:
[email protected]




---------------------------------------------------------------------


To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to