The code below occasionally blows and it's because the using block exits causing a dispose on the "stream" object before the stream has been written fully.
private void DoStuff(Stream input)
{
using (var stream = _httpWebRequest.GetRequestStream())
{
var buffer = new byte[input.Length];
input.Read(buffer, 0, buffer.Length);
stream.Write(buffer, 0, buffer.Length);
stream.Flush();
}
}
The resulting error is: The request was aborted: The request was canceled. ---> System.IO.IOException: Cannot close stream until all bytes are written.