I’m trying to make a small programm to download files via HTTP in C#.
The Basic download with a WebClient works fine, but now i wanted to try
downloading a file with multiple connections.
So far:
HttpWebRequest HttpRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse HttpResponse = (HttpWebResponse)HttpRequest.GetResponse();
Stream ResponseStream = HttpResponse.GetResponseStream();
FileStream FSChunk = new FileStream(destination, FileMode.OpenOrCreate, FileAccess.Write);
while ((BytesThisRead = ResponseStream.Read(Buffer, 0, (int)BytesPerRead)) != 0)
{
FSChunk.Write(Buffer, 0, BytesThisRead);
TotallyRead += BytesThisRead;
if (TotalReadLength - TotallyRead < buffersize)
BytesPerRead = TotalReadLength - TotallyRead;
}
I can download the File using this one ResponseStream, also split up in 2 parts using the one ResponseStream. My problem is, the WebStreams are not seekable, so I can’t just set a position to read from.
How can I manage to download one File over HTTP simultaneously using different Streams (connections, I think one stream can’t be used by multiple members).
I’ve read a lot of articles here and googled for some hours, but I can’t find a solution.
Does Chunked transfer encoding have anything to do with this topic?
Best Regards,
Damon
you need to call
AddRangeon the request – this set acontent rangein thehttp headerwhich tells the server which portion of the file you are asking for.see http://msdn.microsoft.com/en-us/library/dd992108.aspx