无法使用webclient下载

时间:2012-03-23 06:36:17

标签: .net

我无法下载以下链接 远程服务器返回错误:(404)Not Found 请指导我

        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;
            }
        }

1 个答案:

答案 0 :(得分:0)

首先,为什么在下载CSV时将标题设置为接受zip文件?

其次,该URL始终不存在;当我第一次打开这个主题时,链接工作正常。 2分钟后,我刷新了页面,它给了我一个404,几分钟后链接再次运行。如果我是你,我会寻找更稳定的信息来源,因为这个特殊文件似乎非常不可靠。