问题描述
在前端中集成Axios后,调用API时报如下错误:
Failed to execute 'setRequestHeader' on 'XMLHttpRequest': Value is not a valid ByteString
原因分析
- 请求的头信息中不能出现中文或UTF-8码的字符
- 如:
{
url:'/login',
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'x-author': '伍邪'
},
params:{
username: userName,
password: password,
redirect_uri: wxContext.getViewData().redirectUri
},
withCredentials: true
}
修改为如下即可
{
url:'/login',
method: 'post',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'x-author': 'wuxie qq:16349023'
},
params:{
username: userName,
password: password,
redirect_uri: wxContext.getViewData().redirectUri
},
withCredentials: true
}