[英]GET request from server controller using MEAN stack
I'm using MEAN stack with MeanJs. 我正在使用带有MeanJs的MEAN堆栈。 The thing is, I have a task that requires calling a GET request from the server side (Expressjs) to another server (with a different domain name).
问题是,我有一个任务需要从服务器端(Expressjs)到另一个服务器(具有不同的域名)调用GET请求。
The code in the client side (AngularJs) calls: 客户端中的代码(AngularJs)调用:
$scope.getWorkflow = function() {
$http.get('/ezee', $scope.credentials).success(function(response) {
console.log(response.message);
}).error(function(response) {
console.log('error');
});
};
And the corresponding server controller function is: 并且相应的服务器控制器功能是:
exports.list = function(req, res) {
req.get('http://ezslave.io', function(q, r){
res.json({message: r.message}); // just to test
});
};
Obviously, the code below doesn't work. 显然,下面的代码不起作用。 I'm unsure about how to make a GET request from that
list
function. 我不确定如何从该
list
函数发出GET请求。 Am I supposed to use ExpressJs or pure NodeJs for this? 我应该为此使用ExpressJ或纯NodeJ吗? And how to get the correct library loaded?
以及如何加载正确的库?
Use the request module of nodejs : https://github.com/mikeal/request for sending the http request. 使用nodejs的请求模块: https : //github.com/mikeal/request发送http请求。
var request = require("request");
exports.list = function(req, res) {
request("http://ezslave.io",function(err,response,body){
res.send(response);
});
};
Hope this helps you 希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.