在实现了简单下载程序的基本版本之后,我花了几个小时搜索了解如何获取我的URL的类型,如.mp3, .mp4等。诸如日常动作等网站的URL没有在最后附加它。这是因为我的Downloader适用于这些类型,但是没有特定类型的链接会使其下载Kb文件而无法播放。如何从URL中获取数据类型
这里是确定内容类型决定*。扩展名进行下载代码:
WebClient myWebClient = new WebClient();
string datastring = myWebClient.DownloadString("http://www.dailymotion.com/video/x1viyeu_pakistani-actress-meera-reema-saima-dance-on-faisal-ahmed-music-album-launch_news");
NameValueCollection headers = myWebClient.ResponseHeaders;
foreach (string key in headers.AllKeys)
{
Console.WriteLine("Header:{0},Value:{1}", key, headers[key]);
}
这回我的输出在控制台的名单中具有管线是:
页眉:Content-Type,Value:text/html; charset = utf-8
现在我想听听那将如何帮助我解决已经描述的问题。
建议,请
这里是下载
private void downloadbtn_Click(object sender, EventArgs e)
{
WebClient myWebClient = new WebClient();
//Declarations for string objects
string downloadURL, path;
//raw URL taken from user
downloadURL = this.downloadURL.Text;
path = this.savePath.Text;
Uri tmp = new Uri(downloadURL);
string EndPathFileName = tmp.Segments.Last();
path = path + @"\" + EndPathFileName;
//downloads file using async method
myWebClient.DownloadFileAsync(tmp, path);
downloadbtn.Text = "Download Started";
downloadbtn.Enabled = false;
myWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
myWebClient.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
}
你能更具体,我听到etc.but couldn”一样MIME弄清楚。? – 2014-10-04 08:09:37
形象重复是一件相当简单的工作:-) – 2014-10-09 07:31:27
这是之前问过,但现在文本/ HTML有更多的事要做 – 2014-10-09 07:32:13