我正在尝试向我的 nodeJS 后端 API 发出 axios 请求。 我正在使用 Genymotion 并按照以下请求设置:
async componentDidMount() {
const response = await axios.get('http://10.0.3.2:3333/posts');
console.log(response)
}
但我希望获得真实的数据,就像我在浏览器中发出 get 请求时一样:
所以我只在来自其他域的请求时遇到问题
这是mais入口点 Controller :
Routes.js
routes.get('/posts', postController.index);
postController.index
async index(req, res) {
console.log(req)
const post = await Post.find().sort('-createdAt')
return res.json(post)
}
请求未到达console.log
最佳答案
我已经使用自己的 IP 地址解决了这个问题,我复制了我的 IPV6 地址并将其用作发出请求的地址。
关于node.js - 使用 axios 响应 native 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56622651/