header axios code example
Example 1: axios header authorization
const res = await axios.get('https://httpbin.org/get', {
headers: {
authorization: 'my secret token'
}
});
Example 2: header in axios
axios.post('url', {"body":data}, {
headers: {
'Content-Type': 'application/json'
}
}
)
Example 3: headers in axios.get
const axios = require('axios');
const res = await axios.get('https://httpbin.org/get', {
headers: {
'Test-Header': 'test-value'
}
});
res.data.headers['Test-Header'];
Example 4: how to send header in axios
const username = ''
const password = ''
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
const url = 'https://...'
axios.post(url, {
headers: {
'Authorization': `Basic ${token}`
}
})
Example 5: axios set request header
axios.post('http://localhost/M-Experience/resources/GETrends.php',
{
firstName: this.name
},
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});