Endpoint Basic Auth VueJs

问题描述 投票:0回答:1

我试图用用户名和密码访问端点,但控制台给我一个401()

这是我的代码:

created () {
    this.$http.get(URL, {
        username: 'xxxxxxx',
        password: 'xxxxx'
     }).then(response => {
          console.log(response)
        })
 }

这是使用VueJS访问端点的正确方法吗?

http vue.js vuejs2 vue-resource
1个回答
1
投票

您必须提供Base64中编写的用户名和密码。

const encodedUserPswd = btoa(`${user}:${pswd}`);
axios.get(URL, {}, {
  headers: { `Authorization: Basic ${encodedUserPswd}` },
}).then((response) => {
  // ...
});
© www.soinside.com 2019 - 2024. All rights reserved.