javascript - react native : set headers with the Linking api

标签 javascript reactjs react-native

如何在 React Native 中设置 RequestHeader?像下面这样:

var client = new XMLHttpRequest();
client.open("GET", "http://www.example.com/api");
client.setRequestHeader("authorization", "Bearer Access_Token");
client.send();

我在 Linking api 文档中找不到任何信息。 https://facebook.github.io/react-native/docs/linking.html

最佳答案

要向网站发出带有 header 的请求,您需要 http(s) 请求,而不是在 2 个应用程序之间建立链接。

如其他答案所述,链接 api 没有 header 。使用 http(s) 获取远程地址时确实有 header

https://facebook.github.io/react-native/docs/network.html

fetch('https://mywebsite.com/endpoint/', {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    firstParam: 'yourValue',
    secondParam: 'yourOtherValue',
  })
})

关于javascript - react native : set headers with the Linking api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41471979/

相关文章:

javascript - 正则表达式 - 从与表达式不匹配的字符串中删除所有内容

javascript - d3js 径向整洁树 - dx 和 dy 是如何填充的?

javascript - 在将视频上传到数据库之前,如何对 native expo进行压缩?

android - 在调试apk正常工作时 react native 版本apk在启动时崩溃

reactjs - 在 react 应用程序中触发私有(private) channel 的事件

javascript - 什么是显式 promise 构造反模式,我该如何避免它?

Javascript链式解构

reactjs - 模板文字在 react 中不起作用

javascript - 结果到达客户端时,Next JS 服务器端渲染如何工作?

javascript - Node.js Nodemailer 对象数组到 CSV 文件作为电子邮件中的附件