简体   繁体   中英

React Native fetch call working in iOS but not Android

I can't seem to get the following fetch call to work on Android. It's not hitting the server and doesn't seem to be throwing any errors. The same code works on iOS. Do I have to do something special to enable network requests for Android on React Native? Thanks in advance.

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);
    };

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM