我试图用用户名和密码访问端点,但控制台给我一个401()
这是我的代码:
created () {
this.$http.get(URL, {
username: 'xxxxxxx',
password: 'xxxxx'
}).then(response => {
console.log(response)
})
}
这是使用VueJS访问端点的正确方法吗?
您必须提供Base64中编写的用户名和密码。
const encodedUserPswd = btoa(`${user}:${pswd}`);
axios.get(URL, {}, {
headers: { `Authorization: Basic ${encodedUserPswd}` },
}).then((response) => {
// ...
});