简体   繁体   English

React Native提取调用在iOS上有效,但不能在Android上有效

[英]React Native fetch call working in iOS but not Android

I can't seem to get the following fetch call to work on Android. 我似乎无法收到以下fetch调用以在Android上工作。 It's not hitting the server and doesn't seem to be throwing any errors. 它没有命中服务器,似乎也没有引发任何错误。 The same code works on iOS. 相同的代码可在iOS上使用。 Do I have to do something special to enable network requests for Android on React Native? 我是否需要做一些特殊的事情才能在React Native上启用对Android的网络请求? 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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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