问题描述
在这里您可以看到登录请求的响应。 看起来很棒。唯一的事情是,它的主体为空,我不知道如何访问(和本地存储)Bearer令牌。
这是我现在拥有的:
import { Injectable,OnInit } from '@angular/core';
import {
HttpClient,HttpErrorResponse,HttpHeaders,HttpHeaderResponse,} from '@angular/common/http';
@Injectable({
providedIn: 'root',})
export class AuthService implements OnInit {
constructor(private http: HttpClient) {}
ngOnInit() {}
signIn(name: string,password: string) {
var postdata = { name: name,password: password };
this.http
.post('http://localhost:8081/login',postdata,{ observe: 'response' })
.subscribe(
(response) => {
console.log(response);
},(error) => {
console.log('did not work');
}
);
}
如何在头部分添加不记名令牌?我什么都看不到。
解决方法
您尝试过这样吗?
response.headers.get('Authorization'))