【发布时间】:2018-02-18 23:00:35
【问题描述】:
我有一些只能通过 API 网关服务器调用的后端服务。后端服务在 Spring REST 服务中,API GateWay 是一个节点服务器。这两个服务器在不同的端口(后端:8080,节点:3000)上本地运行。
如何从我的节点服务器向后端服务发出请求?
【问题讨论】:
标签: node.js spring http localhost spring-rest
我有一些只能通过 API 网关服务器调用的后端服务。后端服务在 Spring REST 服务中,API GateWay 是一个节点服务器。这两个服务器在不同的端口(后端:8080,节点:3000)上本地运行。
如何从我的节点服务器向后端服务发出请求?
【问题讨论】:
标签: node.js spring http localhost spring-rest
如果他们都暴露了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);
});
但我建议使用 superagent 或 axios 之类的库
【讨论】: