我無法下載到通過以下鏈接下載 遠程服務器返回錯誤:(404)未找到 請指引我無法使用Web客戶端
string st = "http://www.nseindia.com/content/indices/histdata/S&P%20CNX%20NIFTY15-02-2012-22-03-2012.csv";
Uri uu = new Uri(st);
using (WebClient fileReader = new WebClient())
{
string tgtDir;
try
{
fileReader.Headers.Add("Accept", "application/zip");
fileReader.Headers.Add("user-agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 (.NET CLR 3.5.30729)");
tgtDir = @"c:\temp\nif.csv";
fileReader.DownloadFile(uu, tgtDir);
fileReader.Dispose();
}
catch (WebException ex)
{
Label1.Text = ex.Message;
}
}
如果您導航到網址,它有效嗎? (請在這裏問明顯的問題) – Ryan 2012-03-23 06:40:16
我試過了,我在Chrome中得到了404 ... – 2012-03-23 06:43:25
這個URL在我的瀏覽器中也出現了404,所以它不是WebClient實現的問題。 http://www.nseindia.com/content/indices/histdata/S&P%20CNX%20NIFTY15-02-2012-22-03-2012.csv – mellodev 2012-03-23 06:44:00