在这里,您可以看到登录post请求的响应。真不错。唯一的问题是,它有一个空的主体,我不知道如何访问(和本地存储)持有者令牌。
我现在能记录的是:


这就是我现在所拥有的:
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');
}
);
}如何使用持有者令牌访问头部部分?我在任何地方都没看到。
发布于 2020-08-21 22:38:56
你试过这样吗?
response.headers.get('Authorization'))https://stackoverflow.com/questions/63524586
复制相似问题