[英]WebClient (403) Forbidden
我正在使用Dropbox來存儲我的文件,當我使用直接鏈接時,我將獲得HTTP重定向。 但是我可以通過以下方式獲取重定向URI:
var request = WebRequest.Create(MySQLData);
request.Method = "HEAD";
var response = request.GetResponse();
但是我得到“遠程服務器返回錯誤:(403)禁止。” 因此,我添加了一個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");
原來是因為我在URI字符串中使用?raw = 1,而不是?dl = 1。
例如...
string MyDownload = "https://dl.dropboxusercontent.com/u/********/MyFile.zip?dl=1";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.