使用Fetch和Axios处理对服务器的请求,在 Android 模拟器/设备上运行它时,它显示以下错误:
这是请求代码:
fetch(URL,{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: userEmail,
password: userPassword
}),
})
.then((response) => response.json())
.then((responseJson)=>{
Alert.alert("bien");
console.warn(responseJson);
})
.catch((error)=>{
console.error(error);
console.warn(error);
});
Run Code Online (Sandbox Code Playgroud)
小智 16
由于 Http 请求在最新的 Android 更新中不起作用,我认为在 28 号到来之后。因此,您必须将以下属性添加到 AndroidManifest.xml
<manifest
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:usesCleartextTraffic="true">
// ----------------
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18711 次 |
| 最近记录: |