Task
Generally, this is a clone of the question on stackoverflow.com. (No one answers there)
It is necessary to download data in parts through one http request and show changes in progress after each download (physical data sending via the Internet). (It doesn't matter how I show progress, you can just output to the console).
Code
using System; using System.Text; using System.IO; using System.Net; ... public static void UploadData() { const string data = "simple string"; byte[] buffer = new ASCIIEncoding().GetBytes(data); // благодаря http://www.posttestserver.com все сразу работает HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://posttestserver.com/post.php"); req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 " + "(KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10"; req.Accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; req.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3"); req.Headers.Add("Accept-Language", "en-US,en;q=0.8"); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = buffer.Length; req.SendChunked = true; int bytesRead = buffer.Length; const int chunkSize = 3; Stream s = req.GetRequestStream(); for (int offset = 0; offset < bytesRead; offset += chunkSize) { int bytesLeft = bytesRead - offset; int bytesWrite = bytesLeft > chunkSize ? chunkSize : bytesLeft; s.Write(buffer, offset, bytesWrite); } s.Close(); // ВАЖНО: только здесь будут отправлены данные через сеть } Important
Whatever the SendChuncked parameters, AllowWriteStreamBuffering and ContentLength data are never sent over the network after each write to the request stream (everything looked through Fiddler).
Question
How to send data (physically) after each write to the request flow (call to the Write method)?
Limitations:
- .Net 2.0;
- use only HttpWebRequest (WebClient does not fit).



Stream.Flushtried afterStream.Write? - Zergatul