我制作了一个简单的程序(非常依赖于这个例子)来可视化我的问题。它只从指定的 URL 下载文件,仅此而已;在我尝试使用此类数据之前,一切都很好:
令人惊讶的是,什么都没有发生。为什么它既不下载相关视频也不下载 HTML 源代码?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using System.IO;
using System.ComponentModel;
namespace downloader
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void DownloadButton_Click(object sender, RoutedEventArgs e)
{
WebClient client = new WebClient();
string fileName;
try
{
fileName = System.IO.Path.GetFileName(URLBox.Text);
Uri currentURL = new Uri(URLBox.Text);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
client.DownloadFileAsync(currentURL, fileName);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
progressBar.Value = 0;
}
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download Completed!");
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}
}
}