Javascript Axios请求返回401,尽管有授权标头
我正在尝试使用axios将数据修补到django API,使用以下代码段:Javascript Axios请求返回401,尽管有授权标头,javascript,reactjs,axios,Javascript,Reactjs,Axios,我正在尝试使用axios将数据修补到django API,使用以下代码段: nextQuestion=()=>{ 如果(this.state.currentIndex==0)返回; const token=this.props.token; 常量配置={ 标题:{ 授权:`Token${Token}`, }, 数据:{ quiztaker:this.state.data[0].quick.quiztaker\u set.id, 问题:this.state.data[0]。测验。问题集[this
nextQuestion=()=>{
如果(this.state.currentIndex==0)返回;
const token=this.props.token;
常量配置={
标题:{
授权:`Token${Token}`,
},
数据:{
quiztaker:this.state.data[0].quick.quiztaker\u set.id,
问题:this.state.data[0]。测验。问题集[this.state.currentIndex]
身份证件
答案:编号(本州答案),
},
};
console.log(configs);
axios
.patch(“/api/save-answer/”,配置)
。然后((响应)=>{
控制台日志(响应);
})
.catch((错误)=>{
console.log(错误);
});
这是我的国家({
currentIndex:this.state.currentIndex-1
});
};使用axios.patch()
编写,应执行axios.patch(url、数据、配置)…
const data = {
"quiztaker": this.state.data[0].quiz.quiztakers_set.id,
"question": this.state.data[0].quiz.question_set[this.state.currentIndex].id,
"answer": Number(this.state.answer),
};
const token = this.props.token;
const configs = {
"headers": {
"Authorization": `Token ${token}`,
},
};
axios
.patch("/api/save-answer/", data, configs)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
端点需要什么内容类型?@Anuga应用程序/jsontriedaxis.patch(url、数据、配置).
?@Anuga谢谢!将阀体和集管分离工作正常