我在我的 android 设备上使用 expo 客户端并设置了一个 django 服务器,localhost:8000我正在尝试在 react native 中使用 fetch 访问和端点。我看过如何从我的 Android 设备访问我的本地主机? 你如何在Android模拟器中连接本地主机?以及如何从 Eclipse 中的 Android Emulator 连接到我的 http://localhost Web 服务器,但这不起作用。
我也尝试使用我机器的 ip 地址而不是 localhost,但没有结果。这是一个示例代码
componentDidMount(){
return fetch('http://my-ip-address:8000/restapi/')
.then((response) => {
console.log("success")
response = response.json()
}).catch(error => {
console.error(error)
})
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?