【问题标题】:How to communicate between locally running web services如何在本地运行的 Web 服务之间进行通信
【发布时间】:2018-02-18 23:00:35
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    如果他们都暴露了rest 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 之类的库

    【讨论】:

    • 无法在本地 API 之间进行通信,知道如何存档吗?
    猜你喜欢
    • 1970-01-01
    • 2020-07-03
    • 2012-02-16
    • 1970-01-01
    • 2016-08-31
    • 2018-11-03
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    相关资源
    最近更新 更多