繁体   English   中英

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

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

我似乎无法收到以下fetch调用以在Android上工作。 它没有命中服务器,似乎也没有引发任何错误。 相同的代码可在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);
    };

确保您在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