[英]React Native 0.66.* axios call [TypeError: Network request failed] ANDROID
Hi i am new in react native嗨,我是 React Native 的新手
i have macbook and i am running Laravel projects in macbook by using Laravel valet park我有 macbook,我正在使用 Laravel valet park 在 macbook 中运行 Laravel 项目
simple i am trying to generating Auth token by using any API which is developed in laravel 8. when i hit API by using postman then i got 100% response.很简单,我正在尝试使用在 laravel 8 中开发的任何 API 来生成 Auth 令牌。当我使用邮递员点击 API 时,我得到了 100% 的响应。 but when i try to hit this API by using axios in react native always i am getting "NETWROK ERROR" in response.
但是当我尝试通过在 react native 中使用 axios 来访问这个 API 时,我总是收到“NETWROK ERROR”作为响应。
import axios from 'axios';
axios.defaults.baseURL = 'http://cms.test/';
const LoginScreen = ({navigation}) => {
const [email,setEmail] = useState('');
const [password,setPassword] = useState('');
const [user, setUser] = useState(null);
const [error, setError] = useState(null);
const login = async() => {
if(!email || !password){
Alert.alert('Please fill all fields')
}else{
axios.post('api/token', {
email,
password,
device_name: 'mobile',
}, {
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {
const userResponse = {
email: response.data.user.email,
token: response.data.token,
}
setUser(userResponse);
setError(null);
// SecureStore.setItemAsync('user', JSON.stringify(userResponse));
AsyncStorage.setItem('user', JSON.stringify(userResponse));
})
.catch(error => {
console.log(error);
return false;
const key = Object.keys(error.response.data.errors)[0];
setError(error.response.data.errors[key][0]);
})
}
}
Always getting "NETWORK ERROR" in response.总是收到“网络错误”作为回应。
Note: i already updated AndroidManifest.xml file by these below linse注意:我已经通过以下 linse 更新了 AndroidManifest.xml 文件
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
But there is not any change, still getting "NETWORK ERROR", on hit API但是没有任何变化,仍然收到“网络错误”,命中 API
有时,当您的 wifi 网络更改或重新连接时,android 模拟器会遇到网络问题,重新运行您的模拟器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.