Gundam Meister
Gundam Meister

Reputation: 1505

React Native: set headers with the Linking api

How can I setRequestHeader in React Native? Like the following:

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

I can't find any info in the Linking api doc. https://facebook.github.io/react-native/docs/linking.html

Upvotes: 3

Views: 6050

Answers (2)

Lukas Liesis
Lukas Liesis

Reputation: 26403

to make request with headers to website, you need http(s) request, not linking between 2 apps.

As mentioned in other answer, linking api does not have headers. While fetching remote address with http(s) do have headers

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',
  })
})

Upvotes: 4

ide
ide

Reputation: 20788

The Linking API is for linking between apps on the device. There is no notion of headers when linking between apps. Use query parameters in the URL instead.

Upvotes: 1

Related Questions