【问题标题】:Checking Resume Capability with HttpWebRequest Method使用 HttpWebRequest 方法检查恢复能力
【发布时间】:2012-09-03 01:30:59
【问题描述】:

这是我正在使用的代码:

private bool CheckPartialDL(String url)
{
    HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(url);
    hwr.Method = "HEAD";
    hwr.AddRange(0);

    try
    {
        HttpWebResponse hwbresp = (HttpWebResponse)hwr.GetResponse();
        if (hwbresp.StatusCode == HttpStatusCode.PartialContent)
        {
            hwbresp.Close();
            return true;
        }

    }//end of try

    catch (WebException wbe)
    {
        MessageBox.Show(wbe.Message, "Error");
    }//end of catch

    return false;

}//end of Check

但是服务器返回如下错误:

远程服务器返回错误:(416) 请求的范围不可满足。

我要下载以下文件格式:

http://windowsclient.net/sitefiles/1000/wpf/videos/source-code/creatingavideoapp-part1.zip

当我使用 IDM 检查恢复能力时,idm 显示它可用。

那么我提供的代码哪里错了?

【问题讨论】:

  • 小问题,但仅供参考:WebRequest 是 .NET 的一部分,而不是 C# 的一部分。

标签: c# httpwebrequest download httpwebresponse


【解决方案1】:

这是一个包含一些信息的链接

http://www.checkupdown.com/status/E416.html

现在我对可恢复下载及其工作原理有了一点了解,所以我看到的是 您没有为文件提供要下载的正确字节范围。

假设文件大小为 1500 字节。 您必须将范围设置为从 150 到 324。 当然范围不能超过 1500 :)

所以我认为您没有为它提供要检索的合适范围的数据。

更多,检查这个链接问题,它指定范围 字节数 HTTP Request with multiple Ranges

【讨论】:

    【解决方案2】:

    我知道这个问题已经有几年了,但我只是遇到了完全相同的问题(和类似的代码),问题似乎是你不能同时拥有 "Method = 'HEAD'" 和 AddRange( ) 因为删除对 AddRange 的调用工作正常。

    编辑 - 这个post 确认:

    "服务器必须忽略随请求接收的 Range 标头字段 GET以外的方法”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      • 2016-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多