http://blogs.msdn.com/ksharkey/archive/2004/10/17/243656.aspx

... I just needed a rant space. I've just spent 10-20 minutes trying to track down a bug in some code in a Windows Service I was writing, "Cannot close stream until all bytes are written."

  1. Get stream length. Yup, right size
  2. Get ContentLength property. Same
  3. Write both values side by side to EventLog. Values are identical.
  4. repeat 'n' times
  5. Remove ContentEncoding header, assuming it's UTF8. No effect.
  6. Remove ContentLength header. Works. Autocalculated value is what I was looking for... plus two.
  7. AAAAAAAAUGH! Change responseWriter.WriteLine to responseWriter.Write. .... grrrr

Sometimes, even .NET easy isn't easy enough for some people.

在使用HttpWebResponse的时候老师报这个错:System.Net.WebException was unhandled
  Message="请求被中止: 请求已被取消。"
注释这个就好了,ft
//myHttpWebRequest.ContentLength = indata.Length;