尝试在axios.post请求头上加authorization但是返回401,后端没有通过验证,想请教一下怎么写才能正确的发送验证。
submitForm() {
this.$refs.formRef.validate((valid) => {
if (valid) {
axios
.post(
"http:xxx",
this.form,
{
responseType: "blob",
},
{
headers: {
Authorization: "Basic YWRtaW4lM0FwYXNz",
},
}
)
.then((response) => {
const blob = new Blob([response.data], {
type: "application/pdf",
}); //Perform Success Action
var href = window.URL.createObjectURL(blob);
console.log(href);
window.open("/static/pdf/web/viewer.html?file=" + href);
})
.catch((error) => {
console.log(error.response.status); //error.response.status Check status code
})
.finally(() => {
//Perform action in always
});
} else {
this.$message({ message: "Wrong format", type: "error" });
}
});
},
Request Headers: