Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用Node.js访问https URL_Node.js_Xml_Url_Https_Ssl Certificate - Fatal编程技术网

尝试使用Node.js访问https URL

尝试使用Node.js访问https URL,node.js,xml,url,https,ssl-certificate,Node.js,Xml,Url,Https,Ssl Certificate,我正在尝试使用Node.js从HTTPS URL访问XML数据集。我在使用HTTP URL的不同数据集上使用了相同的代码,效果很好 我已经调查过了,但我不知道该怎么办 这是我正在使用的代码 var parseString = require('xml2js').parseString; var https = require('https'); function xmlToJson(url, callback) { var req = https.get(url, function(r

我正在尝试使用Node.js从HTTPS URL访问XML数据集。我在使用HTTP URL的不同数据集上使用了相同的代码,效果很好

我已经调查过了,但我不知道该怎么办

这是我正在使用的代码

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);
    }
})
这是我在命令行中收到的错误。


任何帮助都将不胜感激。

相反,我使用了JSON版本,并使用了以下代码:

var request = require("request")
var url = "https://data.dublinked.ie/cgi-bin/rtpi/realtimebusinformation?stopid=4566&format=json"

request({
    url: url,
    json: true,
    rejectUnauthorized: false
}, function (error, response, body) {

    if (!error) {
        console.log(body) // Print the json response
    }
    else{
        console.log(error)
    }
})
希望有人会觉得这很有用