weixin_58175939 2022-12-13 15:03 采纳率: 100%
浏览 24
已结题

axios在请求头上加authorization

尝试在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:

img

  • 写回答

1条回答 默认 最新

  • Absolute小白 2022-12-13 15:09
    关注
    
    axios.post(' https://domain-name/api/qualification/update', {
         {
                responseType: "blob",
              },
              {
                headers: {
                  Authorization: "Basic YWRtaW4lM0FwYXNz",
                },
    })
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月21日
  • 已采纳回答 12月13日
  • 创建了问题 12月13日