开发者

c# A problem with WebRequest.AddRange() method - seems not to be working?

I want to create my 开发者_运维知识库own multi-threading file downloader, and - as I am reading and alpha-testing some code examples, I've found a weird scenario - when I test the code below, I paste a download link that the server does not supports SeekOperations, so I must dowload the file in 1 thread. When I paste the same download link to e.g FlashGet, I see that the file is segmented and it's being downloaded by 8 threads at the same time. Why ?

            int startPointInt = Convert.ToInt32(startPoint);

            webRequest = (HttpWebRequest)WebRequest.Create(URLTextBox.Text);

            webRequest.AddRange(100, 200);

            webRequest.Credentials = CredentialCache.DefaultCredentials;

            webResponse = (HttpWebResponse)webRequest.GetResponse();

            Int64 fileSize = webResponse.ContentLength;

            strResponse = webResponse.GetResponseStream();

            if (startPointInt == 0)
                strLocal = new FileStream(txtPath.Text, FileMode.Create, FileAccess.Write, FileShare.None);

            else
                strLocal = new FileStream(txtPath.Text, FileMode.Append, FileAccess.Write, FileShare.None);


            int bytesSize = 0;

            byte[] downBuffer = new byte[2048];

            while ((bytesSize = strResponse.Read(downBuffer,0, downBuffer .Length)) > 0)
            {
                strLocal.Write(downBuffer, 0, bytesSize);
            }


A quick googling turned up this link: http://www.developmentnow.com/g/36_2003_12_0_0_203892/WebRequest-GetResponseStream-does-not-suppot-seek-operation--why-.htm

Joerg Joos recommends: "You can use HTTP specific features for partial downloads, such as the "Range" header. Check out the HTTP 1.1 spec for more information on that topic."

Sounds reasonable to me!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜