在邮递员中获取API工作,但在本机反应中不工作

时间:2018-11-10 09:20:23

标签: api react-native fetch

我想在react native中获取我的api,但react不显示我的结果,此api在postman中显示但不显示在react native中,在我更改我的api后,这对我有效但不显示此api。 我的代码是:

fetch('http://roomarket.ir/LlIi1/CT.php')
  .then((response13) => response13.json())
    .then((response3) => {
      this.setState({Alert.alert(response3.ENtime)})

我该如何在本机响应中获取它,请帮助我

2 个答案:

答案 0 :(得分:1)

尝试一下。

print("".join(sorted(tex.split(","))))

答案 1 :(得分:0)

这看起来像是CORS标头问题。显示小样的示例小提琴因域名不同而失败:https://jsfiddle.net/98to6za0/

fetch('http://roomarket.ir/LlIi1/CT.php')
  .then((response13) => response13.json())
    .then((response3) => {
    		console.log(response3);
    });

有了邮递员,它将起作用,因为在URL上没有强制执行cors控件。

需要为cors启用API: CORS with php headers

您可以在此处了解有关CORS的更多信息: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS