const getCustomers = async (token) => {
try {
const response = await axios.get(`${base_url}/customers`, { headers: { 'Authorization': `Bearer ${token}`} })
return response.data
} catch(error) {
logger.error(error)
}
我正在使用axios向api发出请求,但我一直遇到相同的错误。
error: undefined {"config":{"url":"https://api.contaazul.com/v1/customers","method":"get","headers":{"Accept":"application/json","Authorization":"Bearer EU5KBm8ft1ZB4vFy9I89xYQWnzqcbULS","User-Agent":"axios"},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1},"code":"HPE_INVALID_HEADER_TOKEN"}
已经尝试删除node_modules并使用其他版本的节点
答案 0 :(得分:0)
尝试
const getCustomers = async (token) => {
await axios.get(`${base_url}/customers`, {
headers: {
"Authorization": `Bearer ` + token
}
})
.then(response => {
return response.data;
})
.catch(err => {
console.log(err)
});
}