如何在本地运行的Web服务之间进行通信

时间:2017-09-10 16:55:23

标签: node.js spring http localhost spring-rest

我有一些后端服务,只能通过API网关服务器调用。后端服务在Spring休息服务中,API GateWay是节点服务器。这两个服务器在不同端口上本地运行(后端:8080,节点:3000)。

如何从我的节点服务器发出后端服务请求?

1 个答案:

答案 0 :(得分:0)

如果它们都暴露了其他API,您可以使用内置的http模块进行通信

    require('http');
        var options = {
      host: 'www.google.com',
      port: 80,
      path: '/index.html'
    };

    http.get(options, function(res) {
      console.log("Got response: " + res.statusCode);

      res.on("data", function(chunk) {
        console.log("BODY: " + chunk);
      });
    }).on('error', function(e) {
      console.log("Got error: " + e.message);
    });

但我建议使用superagentaxios

等库