2014-02-08 44 views
0

如何使用C#下載http://www.tneu.edu.ua/study/timetable/列出的zip文件之一?下載HTML頁面代替ZIP文件

我已經試過

WebClient webClient = new WebClient(); 
webClient.DownloadFile("http://www.tneu.edu.ua/engine/download.php?id=801", "local.zip"); 

但DownloadFile()方法執行後,在 「local.zip」 接收,而不是實際的zip文件HTML頁面。

在瀏覽器中鼠標點擊相應鏈接時,可以輕鬆下載zip文件。 但是,當我複製並粘貼鏈接網址「http://www.tneu.edu.ua/engine/download.php?id=801」到瀏覽器時,它也將我重定向到根頁面。

我感謝您的幫助!

回答

3

此代碼是:

WebClient webClient = new WebClient(); 
webClient.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate,sdch"); 
webClient.Headers.Add(HttpRequestHeader.Referer, "http://www.tneu.edu.ua/study/timetable/"); 
webClient.DownloadFile("http://www.tneu.edu.ua/engine/download.php?id=801", "local.zip"); 

顯然,網站要你從該特定頁面,所以你需要申請它,如果你是從那裏只提到下載。

+0

你試過了嗎? –

+0

是的,但錯誤粘貼,一秒鐘我會修復。 –

+0

非常感謝,它完美的作品! –