A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Content Length not being sent to client in HTTP headers
Joined: Aug 23, 2010
Jul 12, 2011 08:20:48
I am having some trouble with the
Setting the content length using the out.setContentLength(len) is not working, the headers is not sent
to the client when I monitor the traffic via WireShark, and yet out.println("Content-Length: "+len) works.
Is there an explanation for this?
HttpServletResponse res, ServletOutputStream out out.println("Content-Length: "+len); // this works res.setContentLength(len); // this does not work
Author and all-around good cowpoke
Joined: Mar 22, 2000
Jul 12, 2011 13:08:09
Most likely explanation is that your application has already flushed the headers to the response stream. You need to set all headers before the first write to the response stream just to be safe.
JavaDocs where it is explained that setContentLength has no effect if the headers have already been sent and does not report any error.
rocket mass heater
subject: Content Length not being sent to client in HTTP headers
Downloading Images from server
Chunked transfer-encoding problem
socket communication with AS400...
URL string replacing
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014