这对我来说是一个长期存在的问题,我根本找不到解决方案。
在我的本机项目(react-native-cli)中,我使用 axios 包向服务器发送请求。但是当我用我的安卓手机进行测试时,它给出了 [错误:网络错误]。用模拟器,没问题。
我确定这不是后端问题,因为我已经用多台服务器进行了测试。而且我也使用了 fetch 但得到了同样的错误。
这里是版本信息。
"axios": "^0.19.0",
"react": "16.9.0",
"react-native": "0.61.5",
Run Code Online (Sandbox Code Playgroud)
有时,它也适用于安卓手机。这个问题是最大的谜,我受了很长时间的苦。
遇到过这个问题的人,请给我活着。感谢您的仔细阅读。
有时,即使使用 android 模拟器也无法正常工作。但是在删除原始模拟器并创建新模拟器后,它可以正常工作。
const serverUrl = "https://server.com";
axios.post(serverUrl + "/api/candidates/login", {
"email": this.state.email ,
"password": this.state.password
}, {
headers: {
'Content-Type': 'application/json'
}
}).then((response) => {
console.log(response.data);
}).catch((error) => {
console.log(error);
})
Run Code Online (Sandbox Code Playgroud) 我昨天使用 react-native-cli 构建了新的 React Native 项目。但是当用我的安卓手机运行这个项目时,我在红屏上出现了这个错误。
不变违规:WebView 已从 React Native 中删除。现在可以从“react-native-webview”而不是“react-native”安装和导入它。请参阅“ https://github.com/react-native-community/react-native-webview ”。
我从未使用过 WebView,这是我的“package.json”。
{
"name": "",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-image-slider": "^2.0.3",
"react-native-svg": "^9.13.6",
"react-navigation": "^4.0.10",
"react-navigation-drawer": "^2.3.3",
"react-navigation-stack": "^1.10.3",
"react-redux": "^7.1.3",
"redux": "^4.0.4"
},
"devDependencies": {
"@babel/core": "^7.7.5",
"@babel/runtime": "^7.7.6",
"@react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.7.2",
"install-peers": "^1.0.3",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.57.0",
"react-native-gesture-handler": "^1.5.2", …Run Code Online (Sandbox Code Playgroud)