Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

WebClient - 403 Forbidden

$
0
0

I am trying to write some code to download file from an url. But this seemingly trivial function doesn't work. I have explored lot of variations (based on some earlier posts): url encoding, user agent, content type, stream based downloads etc. and nothing seems to work (while the url works perfect with Internet Explorer).

url="http://www.nseindia.com/content/historical/DERIVATIVES/2013/NOV/fo14NOV2013bhav.csv.zip"

        public void NewDowloadFile(string url, string filepath)
        {
            WebClient objWebClient = new WebClient();
            Uri uriWebClient = new Uri(url);
            objWebClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
            objWebClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
            objWebClient.Headers.Add("Content-Type", "application / zip, application / octet - stream");
            objWebClient.DownloadFile(uriWebClient, filepath);
        }

I used Fiddler and could see the following response:

<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD><BODY><H1>Access Denied</H1>
You don't have permission to access "http&#58;&#47;&#47;www&#46;nseindia&#46;com&#47;content&#47;historical&#47;DERIVATIVES&#47;2013&#47;NOV&#47;fo14NOV2013bhav&#46;csv&#46;zip" on this server.<P>
Reference&#32;&#35;18&#46;14c7387d&#46;1385735320&#46;33b58ded</BODY></HTML>

I am really puzzled, any help highly appreciated.

Thanks


Thanks - Mukesh


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>