标头中的角度存储承载令牌

问题描述

在这里您可以看到登录请求的响应。 看起来很棒。唯一的事情是,它的主体为空,我不知道如何访问(和本地存储)Bearer令牌。

我现在可以登录的是:

enter image description here

enter image description here

这是我现在拥有的:

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'))

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...