React Native Android api调用将“错误:网络错误”返回到本地数据库

时间:2019-07-23 20:18:29

标签: typescript api react-native axios

使用axios并承诺调用本地数据库api,无论尝试如何,我都无法到达端点,我不断收到“错误:网络错误”控制台反馈,而没有任何关于问题的真正信息。

我通过使用android系统本地主机https://10.0.2.2:5001/api/[endpoint]提供了正确的端点,当我在chrome浏览器中转到该端点时,它显示了正确的JSON,但是应用程序似乎无法获取数据。 / p>

清单的Internet权限已打开。

axios
    .get('https://10.0.2.2:5001/api/[endpoint]')
    .then(response => console.log(response))
    .catch(error => console.log(error));

1 个答案:

答案 0 :(得分:0)

因此,获得仿真器的可行方法是使用ngrok,然后运行ngrok http https://localhost:[port] -host-header="localhost:[port]"

这会将localhost端口转发到可以调用的网站。