簡體   English   中英

使用MEAN堆棧從服務器控制器獲取GET請求

[英]GET request from server controller using MEAN stack

我正在使用帶有MeanJs的MEAN堆棧。 問題是,我有一個任務需要從服務器端(Expressjs)到另一個服務器(具有不同的域名)調用GET請求。

客戶端中的代碼(AngularJs)調用:

$scope.getWorkflow = function() {
    $http.get('/ezee', $scope.credentials).success(function(response) {
            console.log(response.message);
        }).error(function(response) {
            console.log('error');
        });
};

並且相應的服務器控制器功能是:

exports.list = function(req, res) {
   req.get('http://ezslave.io', function(q, r){
       res.json({message: r.message}); // just to test
   });
};

顯然,下面的代碼不起作用。 我不確定如何從該list函數發出GET請求。 我應該為此使用ExpressJ或純NodeJ嗎? 以及如何加載正確的庫?

使用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);
    });          
   };

希望這對您有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM