【发布时间】:2017-02-07 23:17:36
【问题描述】:
我正在尝试使用 Node.js 从 HTTPS URL 访问 XML 数据集。我已将相同的代码用于不同的数据集,该数据集使用 HTTP URL 并且运行良好。
我已经研究了这个https://www.npmjs.com/package/ssl-root-cas,但我不知道应该怎么做。
这是我正在使用的代码。
var parseString = require('xml2js').parseString;
var https = require('https');
function xmlToJson(url, callback) {
var req = https.get(url, function(res) {
var xml = '';
res.on('data', function(chunk) {
xml += chunk;
});
res.on('error', function(e) {
callback(e, null);
});
res.on('timeout', function(e) {
callback(e, null);
});
res.on('end', function() {
parseString(xml, function(err, result) {
callback(null, result);
});
});
});
}
var urlTrain = "https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation?stopid=7602&format=xml";
xmlToJson(urlTrain, function(err, data) {
if (err) {
return console.err(err);
}
else{
console.log(data);
console.log(data.busstopinformation);
console.log(data.busstopinformation.results);
console.log(data.busstopinformation.results.result[0]);
console.log(data.busstopinformation.results.result[0].shortname);
}
})
这是我在命令行中收到的错误。 Link
任何帮助将不胜感激。
【问题讨论】:
标签: node.js xml url https ssl-certificate