axios post headers authorization 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: axios set authorization header
const username = ''
const password = ''
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')
const url = 'https://...'
axios.post(url, {
headers: {
'Authorization': `Basic ${token}`
}
})
Example 4: axios default headers authorization
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
Example 5: axios post headers authorization
axios.post("url","Data").then(res => {
console.log(res)
localStroge.setItem("access",accessToken)
localStroge.setItem("refresh",refreshToken)
})