我正在尝试使用c#webclient从以下链接下载csv文件:
http://www.tase.co.il/_layouts/Tase/ManagementPages/Export.aspx?sn=none&enumTblType=allShares&Columns=noneColumns&Titles=noneTitles&action=1&SubAction=0&GridId=33&CurGuid={26F9CCE6-D184-43C6-BAB9-CF7848987BFF}&ExportType=3
这个链接可以在我的浏览器中正常工作;但是当我使用以下代码时它不起作用
WebClient ta = new WebClient();
ta.DownloadFileAsync(new Uri("http://www.tase.co.il/_layouts/Tase/ManagementPages/Export.aspx?sn=none&enumTblType=allShares&Columns=noneColumns&Titles=noneTitles&action=1&SubAction=0&GridId=33&CurGuid={26F9CCE6-D184-43C6-BAB9-CF7848987BFF}&ExportType=3"), "s.csv");
我得到一个空的s.csv文件大小:0个字节。我能做些什么?
我尝试了您的代码,它为我返回了相同的结果。我注册了“ DownloadProgressChanged”事件,可能会看到异常:
System.Net.WebException:远程服务器返回错误:(403)禁止。
根据以下链接添加用户代理标头可以解决此问题:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句