I am trying to download a file from a website using the following code:
WebClient webClient = new WebClient();
webClient.DownloadFile("http://www.nseindia.com/content/historical/EQUITIES/2011/MAR/cm07MAR2011bhav.csv.zip", @"c:\myfile.txt");
The exception shown is “forbidden error 403”
It means page not found but I can download that file using java code and also I can directly download it from that website.
How do I download this using C# code?
I tested that URL with wget, and got a 403 error. I was able to solve that problem by adding a user-agent string to the header
Try adding a user-agent string to the header, using
webClient.Headers.Add(HttpRequestHeader.UserAgent, "blah")