是否可以在 Controller 中发出请求?我尝试过使用 node.js http 模块,但没有成功。还有其他方法可以做到这一点吗?
最佳答案
好的,我设法使用另一个模块“请求”解决了这个问题。我做了什么:
在您的项目中安装模块:
npm install -S request
在你的代码中你应该有:
var request = require('request');
request.get({
url: <your url>
}, function(error, response, body) {
if (error) {
sails.log.error(error);
}
else {
sails.log.info(response);
sails.log.info(body);
}
});
关于javascript - 在 Controller 中发出 HTTP 请求 - sails.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30523872/