IvanF.
IvanF.

Reputation: 543

Pass headers as parameter to a javascript post request (react-native)

I'm passing the body parameters this way:
body: JSON.stringify(parameters),
where parameters is structured like parameters.name = 'name', ...
I would like to accomplish the same with the headers but the key (of the key/value) contains -.

headers: {
    'X-Public-App-Authentication': 'Token ' + token,
    'content-type': 'application/json'
},

how can I pass this header as a parameter so I can just write headers: JSON.stringify(heads), ?

Upvotes: 0

Views: 1160

Answers (1)

Andrew
Andrew

Reputation: 28539

The following are the same parameters.name and parameters['name']

So you could do the following

headers['X-Public-App-Authentication'] = 'Token ' + token

Upvotes: 1

Related Questions