node.js - 使用 axios 响应 native 请求

标签 node.js react-native asynchronous axios genymotion

我正在尝试向我的 nodeJS 后端 API 发出 axios 请求。 我正在使用 Genymotion 并按照以下请求设置:

async componentDidMount() {
            const response = await axios.get('http://10.0.3.2:3333/posts');

            console.log(response)
    }

我收到以下回复: Request response

但我希望获得真实的数据,就像我在浏览器中发出 get 请求时一样: enter image description here

所以我只在来自其他域的请求时遇到问题

数据字符串: enter image description here

这是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/

相关文章:

javascript - React Native CameraRoll 权限被拒绝

jquery - ajax异步: true statement execution order

javascript - react Hook : Access to state inside an external function

javascript - 如何以 Angular 异步初始化应用程序

node.js - Upstart 和 node.js 应用程序 "stop: Unknown instance:"

node.js - Nodejs gm 库 - 如何创建多个图像按顺序分层的转换命令

javascript - Express.js 中设置和获取 cookie 失败

node.js - Electron 伪造: missing some dependencies

javascript - NPM 无法识别我的模块(需要未知模块)

ios - 是否可以在不拥有 iPhone 的情况下发布 iOS 应用程序?在 Xcode 上找不到配置文件