我是一个反应原生的新手。每次我尝试提取时,我都会得到这个错误
[TypeError:网络请求失败]
下面是代码:
fetch("http://192.168.20.137:3000/posts", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(memberID),
})
.then((res) => res.json())
.then((data) => Alert.alert(data))
.catch((err) => console.log(err));
}; ```
在AndroidManifest.xml 中添加这些代码行
<application
....
....
android:usesCleartextTraffic="true">
然后,尝试在真实的物理设备中运行代码,而不是在模拟器中,要在物理设备上运行-连接您的usb并尝试运行npx react native run android