This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
I was experiencing the same Content-Length: 0 issue with a different Java versions and for seemingly different reasons, or Jeff's code example is not complete.
I tried bumbling through setting up some code to POST to a server using URL and HttpURLConnection and every time the server would not only show Content-Length 0, but the data I was trying to write was also missing as proved by wireshark captures so the Content-Length value of 0 was correct.
Searching around I first got worried that I was experiencing bug id 6997628, "HttpURLConnection strips Content-Length header on Post". I tried different Java 1.6 versions and different JRE's on different OS's. Then I found the tutorial for reading from and writing to an HttpURLConnection  and that worked. It didn't make sense. My code said I was writing, but as far as I could tell I was not.
Finally I found the difference between the example code and mine. I will re-write the example code with my "mistake" in it:
Moving the write statements to after the getInputStream call seems to ignore them, probably because getInputStream calls connect() and sends the request so that it can have something to read. I don't know how I was suppose to figure this out other than .
I tried reproducing Jeff Gaer's issue, but his code snippet didn't send anything, not even the URL, until I added the getInputStream call (connect() alone didn't do the trick.) Once I did, it would set the correct Content-Length. It continued to work even after commenting out all the setRequestProperty calls and the setRequstMethod call. (Note that those calls are missing from the example.) I was expecting to see an issue with the claimed content-length not matching the written amount ("test" vs "this is a test!" and the extra linefeed) but it worked anyway. I didn't try this on Java 1.4, nor do I care to dig that up to try.