当试图连接到API时,我得到以下错误:
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Authorization"]
请注意,我已经验证了API键(JWT)没有任何回车返回、新行或选项卡。在Postman中测试API密钥和端点是成功的。
代码(测试验证键不包含回车、新行和选项卡):
console.log(/\t\r\n/.test(api_config.API_KEY)); // test to determine if key has carriage returns, new lines, or tabs
const connectionConfig = {
headers: {
'Authorization': 'Bearer ' + api_config.API_KEY
}
}
axios.get(api_config.BASE_URL + api_config.CAMPUSES_OPTIONS_URI, connectionConfig)
.then((response) => {
console.log(response.data);
})
.catch((err) => {
console.log(err)
})
发布于 2021-08-29 03:51:25
你用邮递员测试过API吗?
如果这是可行的,您可以很容易地根据您的API创建带有头、正文等的代码片段。
发布于 2021-08-29 08:11:07
尝试在标头中添加更多的描述
const connectionConfig = {
headers: {
'Authorization': 'Bearer ' + api_config.API_KEY,
'X-Requested-With': 'XMLHttpRequest'
}
}
https://stackoverflow.com/questions/68969387
复制相似问题