我正在尝试使用角度和弹簧安全性进行基本认证。问题是,当我尝试使用邮递员获得某些东西时,它可以完美地工作,而使用角度管理器时,它并不需要进行身份验证来获取数据。
角度代码:
const header = new HttpHeaders(credentials ? {
authorization : 'Basic ' + btoa(credentials.username + ':' + credentials.password)
} : {});
console.log(header.get("authorization"));
this.http.get('http://localhost:8090/user?username='+credentials.username,{ headers : header }).subscribe(response => {
if (response["username"]) {
this.authenticated = true;
this.router.navigate(["user"]);
} else {
this.authenticated = false;
}
我得到的答复:
在邮递员中,它工作得很好:
我在角度代码中写错了吗?