【发布时间】:2019-06-12 15:33:26
【问题描述】:
我正在尝试向服务器发送一个获取请求。但是我收到以下错误,知道如何避免错误吗?
错误:
events.js:183 投掷者; // 未处理的“错误”事件 ^
错误:连接 ECONNREFUSED ****** 在 Object._errnoException (util.js:992:11) 在 _exceptionWithHostPort (util.js:1014:20) 在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
我的要求:
var https = require("https");
// Update these options with the details of the web service you would like to call
var options = {
method: 'GET',
uri: 'https:*****',
resolveWithFullResponse: true,
json: true
};
var req = https.request(options, res => {
res.setEncoding('utf8');
var returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ' + JSON.stringify(returnData))
var pop = JSON.parse(returnData).population;
callback(pop);
});
});
req.end();
【问题讨论】:
标签: javascript node.js get-request