小编csu*_*sum的帖子

React Native fetch api 不适用于 localhost、IP 甚至 10.0.2.2

我在我的 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)

我在这里做错了什么?

django android react-native fetch-api expo

4
推荐指数
1
解决办法
6689
查看次数

标签 统计

android ×1

django ×1

expo ×1

fetch-api ×1

react-native ×1