我已經制作了一個簡單的程序(緊密依靠this示例),它可視化我的問題。它只從指定的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;
}
}
}
它下載的是什麼? – 2012-07-27 01:14:38
@JohnMitchell在這種情況下,沒有下載。 – 0x6B6F77616C74 2012-07-27 01:19:53
因爲它的YouTube鏈接...谷歌正在保護他們的知識產權... – 2012-07-27 01:28:51