React Native Fetch授权标头不起作用

时间:2020-08-14 23:28:06

标签: javascript node.js reactjs react-native api

我最近设置了一个REST API,以使用他们的许可证密钥对我的用户进行身份验证,并使用axios在Node.js中对其进行了测试,并且效果很好。看起来就是这样:

var config = {
  method: 'get',
  url: 'https://myapi?key=mykey',
  headers: {
    'Authorization': 'myauthorization',
  }
};
axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});


如预期般返回{success: true}

但是,当我尝试使用fetch在React Native中做同样的事情时,它根本不起作用,每次都得到{success: false}

let auth = await fetch("https://myapi?key=mykey", {
        method: 'GET',
        headers: {
          'Authorization': 'myauthorization'
        }
      });
      auth = await auth.json();
      console.log(JSON.stringify(auth))

知道为什么会这样吗?

0 个答案:

没有答案