On Thu, 2010-04-29 at 22:07 -0500, hanasaki wrote: > Unfortunately my code is hitting a servlet not under my control which > depends on the content length being set to the actual number of bytes. > > * note: the content is in an InputStream and thus its full length is not > known (could be a file, pipe from someplace else [ex: with > IOUtils.copy(input,output], etc..} > > A POST with the java.net classes seems to send up the content length (I > do not set the header at all myself) while the httpclient 4.x libs pass > up -1 in.
No, it does not. HttpClient does not generate a content-length header when content chunking is used. See it for yourself by turning on the wire logging http://hc.apache.org/httpcomponents-client-4.0.1/logging.html > The goal is to get httpclient to do what the java.net lib > does so I can use httpclient instead of java.net (it is used in all the > rest of the code and having two API's makes maintenance a bit harder for > some of the team). > > Like it or not, that is the server that needs to be communicated with. > Can httpclient be made to function as java.net does? how? > Wrap the original entity with the BufferedHttpEntity class to buffer the content in memory. This will enable HttpClient to generate a valid Content-Length instead of falling back onto more efficient chunk coding. Oleg --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
