我使用以下代码从 C# windows 应用程序中的特定 url 下载文件。
private void button1_Click(object sender, EventArgs e)
{
string url = @"DOWNLOADLINK";
WebClient web = new WebClient();
web.DownloadFileCompleted += new AsyncCompletedEventHandler(web_DownloadFileCompleted);
web.DownloadFile(new Uri(url), @"F:\a");
}
void web_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("The file has been downloaded");
}
但是这条线有一个错误:web.DownloadFile(new Uri(url), @"F:\a");
它说 :
WebClient 请求期间发生异常。