我无法将我的 Expo 应用程序连接到本地主机 Api

问题描述 投票:0回答:1

我正在使用 expo 构建一个 React Native 应用程序,并且我正在尝试连接到在我的本地主机上运行的

http://localhost/api
。我得到的只是网络错误。

expo应用程序正在真实设备上运行。我用

expo start --localhost --android

做到了

我尝试使用

ipconfig /all
提供的 IP 地址而不是本地主机,但我仍然得到
Network Error

这是我的代码

  const fetchApi = async () => {
try {
  const res = await axios.get("http://10.2.0.56:8000/");
  console.log(res.data);
} catch (error) {
  console.log(error.message);
}

};

请有人帮忙

javascript reactjs react-native axios
1个回答
0
投票

我也遇到了同样的问题,请问你解决了吗?

© www.soinside.com 2019 - 2024. All rights reserved.