【问题标题】:WebClient (403) ForbiddenWebClient (403) 禁止
【发布时间】:2015-02-10 19:21:20
【问题描述】:

我正在使用 Dropbox 来存储我的文件,当我使用直接链接时,我会得到一个 HTTP 重定向。但是我可以通过...获取重定向 URI。

            var request = WebRequest.Create(MySQLData);
            request.Method = "HEAD";
            var response = request.GetResponse();

但是我得到“远程服务器返回错误:(403) Forbidden。”然后我添加了一个 User-Agent 标头,但它仍然返回相同的错误。我不确定接下来要尝试什么。

  WebClient wc = new WebClient();
            wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(MySQLData_Check);
            wc.DownloadFileCompleted += DownloadCompleted_MySQLData;

            var request = WebRequest.Create(MySQLData);
            request.Method = "HEAD";
            var response = request.GetResponse();


            wc.Headers.Add("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
            wc.DownloadFileAsync(new Uri(response.ResponseUri.ToString()), RootWindow_TextBox_SaveToDir.Text + "/" + "MySQLData");

【问题讨论】:

  • 通过代理?还是你绕过代理?
  • @NeillVerreynne 我不会通过代理,也不会绕过代理。
  • 尝试把header改成:wc.Headers.Add("User-Agent: Other")

标签: c#


【解决方案1】:

原来是因为我在 URI 字符串中使用了 ?raw=1,而不是 ?dl=1。

例如...

string MyDownload = "https://dl.dropboxusercontent.com/u/********/MyFile.zip?dl=1";

【讨论】:

    猜你喜欢
    • 2011-03-17
    • 2020-05-11
    • 2013-11-28
    • 1970-01-01
    • 2013-11-12
    • 2021-09-23
    • 2015-11-18
    • 2019-08-24
    • 2013-02-09
    相关资源
    最近更新 更多