0
我正在下載託管在Dropbox中的文本文件。但是我在Completed函數中得到了400錯誤代碼。我發現問題只與保管箱託管的文件有關。我可以下載其他示例文本文件,例如「http://wordpress.org/plugins/about/readme.txt」。使用WebClient下載Dropbox文件時出錯
以下是我用於從保存箱下載文本文件的代碼片段。
void downloadFile()
{
WebClient webClient = new WebClient();
NetworkCredential Credentials = new NetworkCredential(<username>, <password>, "<domain>);
webClient.Proxy = WebRequest.GetSystemWebProxy();
webClient.Proxy.Credentials = Credentials;
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadFileAsync(<downloadfileurl>, @"C:\test.txt");
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
if (e.Error == null)
{
MessageBox.Show("Successfully downloaded");
}
else
{
MessageBox.Show(e.Error.ToString());
}
}
以下是錯誤我得到:
System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)
任何支持調整這個問題將得到高度讚賞。
注意:我也試過使用WebRequest(POST),但也有同樣的錯誤。
在此先感謝。