我在一个微服务中有以下代码,该代码调用了另一个:
<div style={{ width: "500px", position: "absolute" }}>
<img src={currentItem.url} style={imageStyle} />
</div>
在调用的微服务中,我有以下代码:
axios.get('http://localhost:4210/usermicroservice/heartbeat')
.then(function(resp) {
console.log('USER HEARTBEAT CALLED ')
})
.catch(function(error) {
console.log('USER HEARTBEAT ERROR ', error)
})
我收到以下错误:
server.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
next();
})
server.get('/usermicroservice/heartbeat', (req, res) => {
console.log('\n*** USER MICROSERVICE CALLED ***')
res.json({});
})
const PORT = 4210;
server.listen(PORT, () => {
console.log(`hsupp01 UserMicroservice server running on port: ${PORT}`)
})
我可以使用相同的网址从Postman访问被调用的微服务:
{ Error: connect ECONNREFUSED 127.0.0.1:4210
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 4210,
答案 0 :(得分:0)
该错误消息不能解决问题,但是下面的代码必须在异步块中执行。
axios.get('http://localhost:4210/usermicroservice/heartbeat')
.then(function(resp) {
console.log('USER HEARTBEAT CALLED ')
})
.catch(function(error) {
console.log('USER HEARTBEAT ERROR ', error)
})