使用.NET webclient从nseindia下载Bhavcopy时出现错误,远程服务器返回错误:(403)禁止
问题描述:
以下代码来自codeproject中的一个线程会出错。
远程服务器返回错误:(403)禁止
文件可以使用下载管理器下载。
我尝试过:
Following code from one of the thread in codeproject gives error.
"The remote server returned an error: (403) Forbidden"
file can be downloaded using download manager.
What I have tried:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
Dim wc As New WebClient
Dim fileurl As String = "http://www.nseindia.com/content/historical/EQUITIES/2012/AUG/cm28AUG2012bhav.csv.zip"
Dim filelocation As String = "d:\aaaaa.zip"
wc.Headers("Accept") = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
wc.Headers("User-Agent") = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1"
wc.DownloadFile(fileurl, filelocation)
Catch exception As Exception
MsgBox("CAnnot Download")
End Try
End Sub
答
执行消息告诉您的操作。或联系网站管理员寻求帮助。
Do what the message tells you. Or contact the site administrators for help.