【问题标题】:Network request failed react native 0.64.0 on https live server but in postman api working fine网络请求在 https 实时服务器上反应原生 0.64.0 失败,但在邮递员 api 中工作正常
【发布时间】:2021-05-19 05:25:11
【问题描述】:
const requestOptions = {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        "username": "mukesh",
        "password": "1234"
      })
    };


 var url = 'http://ewayswork.com:9000/customer/'
    fetch(url, requestOptions)
    .then(response => response.json())
    .then(data => {
      console.log(data)
    })
    .catch(function(error) {
      console.log('Problem with your fetch operation: ' + error.message);
      
    });

【问题讨论】:

  • 请同时上传您的网址。

标签: react-native fetch rest


【解决方案1】:

这是一种可能。

当您使用 react-native 时,您必须使用模拟器或真实设备来检查您的应用。

如果您使用localhost,则无法访问您的 API。相反,您需要在本地 IP 地址上运行服务器。

要获得它,请转到设置 >> 网络 >> wifi >> your_connected_wifi。在底部,复制ipv4 address

然后,在该 ipadress 上运行服务器并相应地更改您的 url。

例如,

如果你使用 django_rest_framework,在你的本地 IP 地址上运行服务器;

python manage.py runserver <Your ip address>

【讨论】:

  • 在邮递员中,我使用此 url 进行发布请求工作正常,结果为 { "CODE": 200, "error": "", "success": "success", "data" : "" }
  • 对此有任何想法吗?
  • 对不起,但我想到的唯一可能性,我发布了。另一种可能性可能是您在 url 中遗漏了一些东西,例如尾部斜杠(/),或者您写错了。
  • 我已经在另外两个应用程序上工作过,提取没有问题,它只发生在 0.64.0 反应本机版本
【解决方案2】:

打开 Cmd 并输入: ipconfig ,检查 ipv4 是否与您在 url 中输入的 ip 相同(不要使用 localhost ,而是使用您的 ip)。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-06-04
  • 2018-01-26
  • 1970-01-01
  • 2021-12-23
  • 1970-01-01
  • 2016-05-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多