axios get authorization header from response code example
Example 1: axios header authorization
const res = await axios.get('https://httpbin.org/get', {
headers: {
authorization: 'my secret token'
}
});
Example 2: add authorization header axios
const res = await axios.get('https://httpbin.org/get', {
headers: {
'Authorization': 'my secret token'
}
});
Example 3: send token in axios header
const username = ''
const password = ''
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
const url = 'https://...'
const data = {
...
}
axios.post(url, data, {
headers: {
'Authorization': `Basic ${token}`
},
})