我想部分下载 url 中的文件。但它返回错误的内容大小,我不知道为什么。远程文件有Accept-Ranges=bytes
怎么解决?
long start = 536871935, end = 805306878;
string url = "http://ipv4.download.thinkbroadband.com/1GB.zip";
var request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362";
request.AllowAutoRedirect = true;
request.Method = "GET";
request.Timeout = 5000;
request.ReadWriteTimeout = 3000;
request.AddRange(start, end);
var response = (HttpWebResponse)request.GetResponse();
if (response.ContentLength != end - start + 1)
throw new Exception(string.Format("Returned content size is wrong; start={0}, end={1}, returned = {2}, shouldbe = {3}",
start, end, response.ContentLength, end - start + 1));
Downloadmanager.exe 中出现“System.Exception”类型的异常,但未在用户代码中处理
附加信息:返回的内容大小错误 start=536871935,end=805306878,返回=536869889,应该=268434944