React-native - Axios GET 请求在 Android 模拟器中抛出网络错误

React-native - Axios GET request throws network error in Android emulator

我是 React-native 的新手。我正在尝试使用以下代码执行简单的获取请求:

axios.get('http://push-cycling-backend.dev/api/test')
    .then((response) => {
        console.log(response);
    })
    .catch((error) => {
        console.log(error);
    });

我已经使用 Postman 测试了请求并且一切正常,但是当我 运行 使用 ANDROID 模拟器在我的 react-native 应用程序中请求时,我收到以下错误:

Error: Network Error

我感觉这是因为我试图通过 Android 模拟器访问通过 Xammp 在本地托管的 Api 端点,但我不知道该怎么做。 请任何指导将不胜感激。 亲切的问候, 马特

我设法通过将请求从 http://push-cycling-backend.dev/api/test to http://10.0.2.2:80/push-cycling-backend/public/api/test 更改为 URL 使其正常工作。据我了解,由于 android 模拟器模拟了一个实际设备,我相信 'localhost' 指的是模拟设备上的地址,而不是我的本地服务器 10.0.2.2 类似于一个关键字,指的是到您本地机器的 ip 地址。