【发布时间】:2021-12-10 20:25:05
【问题描述】:
我叫 Leo,我是 Reactnative 的新手 我正在尝试登录我的应用程序,但遇到了 fetch API 问题。 我收到 [TypeError:网络请求失败]。我在设备 API 30 上运行 这是我的代码:
const loginHadle = async(email, password)=>{
await fetch ('http://127.0.0.1:8000/login/',{
method:'POST',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"email": email, "password":password})
}).then(response=>{
if(response.status==200)
{
response.json().then(data=>{
signIn(data.email, data.tokens);
})
}
})
.then(res => {
console.log("reponse :", res);
}).catch(error => {
console.error(error);
return { name: "network error", description: "" };
});
}
我已经将此行添加到 AndroidManifest.xml
android:usesCleartextTraffic="true"
非常感谢!
【问题讨论】:
标签: android react-native api android-emulator localhost