我们如何通过角度获取Json网络令牌?

问题描述 投票:-1回答:1

我在Spring启动应用程序中有一个休息服务。

我有一个方法,接受用户名和密码作为json数据并检查这些数据,如果它们是真的那么服务返回JWT令牌。

enter image description here

当我通过angular调用此方法时,我无法获得授权令牌并请求发送两次。

enter image description here

为什么请求发送两次,如何获得角度令牌?

import {Component, OnInit} from '@angular/core';
import {Payment} from './Payment';
import {HttpClient, HttpResponse} from '@angular/common/http';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

  title = 'Home';
  constructor(private http: HttpClient) {
  }

  ngOnInit() {

    this.http.post('http://localhost:8084/login', JSON.stringify({ username: 'mehman', password: 'mehman' }), { observe: 'response' })
      .subscribe((response: HttpResponse<any>) => { console.log(response); });
  }
}
angular spring-boot authentication spring-security
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.