var http = require('http'),
fs = require('fs'),
request = require('request'),
AdmZip = require('adm-zip'),
out = fs.createWriteStream('data/nseeqbhav.zip'); // For saving NSE Equity bhavcopy
// Downloading NSE Bhavcopy
var req = request(
{
method: 'GET',
uri: 'https://www.nseindia.com/content/historical/EQUITIES/2017/APR/cm26APR2017bhav.csv.zip',
headers: { "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11",
"Referer": "http://www.nseindia.com/products/content/all_daily_reports.htm",
"Accept-Encoding": "gzip,deflate,sdch",
"encoding": "null",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Cookie": "cookie"
}
}
);
req.pipe(out);
The above code throws the below error :
error: { Error: unable to get local issuer certificate at Error (native) at TLSSocket. (_tls_wrap.js:1079:38) at emitNone (events.js:86:13) at TLSSocket.emit (events.js:185:7) at TLSSocket._finishInit (_tls_wrap.js:603:8) at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:433:38) code: 'UNABLE_TO_GET_IS SUER_CERT_LOCALLY' } statusCode: undefined body: undefined
But when I try to download the same file in c# code using WebClient, it works
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Only a test!");
webClient.DownloadFile("https://www.nseindia.com/content/historical/EQUITIES/2017/APR/cm26APR2017bhav.csv.zip", @"D:\testDownload\cm26APR2017bhav.csv.zip");
Thanks
via user2104242
No comments:
Post a Comment