【问题标题】:React Native fetch call working in iOS but not AndroidReact Native fetch 调用适用于 iOS 但不适用于 Android
【发布时间】:2017-02-02 12:36:42
【问题描述】:

我似乎无法在 Android 上获得以下 fetch 调用。它没有击中服务器,似乎也没有抛出任何错误。相同的代码适用于 iOS。我是否必须做一些特别的事情才能在 React Native 上启用 Android 的网络请求?提前致谢。

export const login = function(user, success, error) {
        let path='http://localhost:3000/api/session';
        fetch(path, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({user: user})
        }).then((response) => {
            return response.json();
        }).then(success).catch(error);
    };

【问题讨论】:

  • 我也有同样的问题。您是如何使用此 API 的?

标签: android ios reactjs react-native


【解决方案1】:

确保您在AndroidManifest.xml 中的android/app/src/main 中设置了以下权限

<uses-permission android:name="android.permission.INTERNET" />

【讨论】:

    猜你喜欢
    • 2020-10-04
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多