如何在 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/