【发布时间】:2018-04-18 07:47:56
【问题描述】:
import {Component, OnInit} from '@angular/core';
import {HttpClient, HttpErrorResponse, HttpResponse} from '@angular/common/http';
@Component({
selector: 'git',
templateUrl: './git.component.html'
})
export class GitComponent implements OnInit {
constructor(private http: HttpClient) {
}
ngOnInit(): void {
const headers = {authorization: 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzYXNobyIsImF1dGgiOiJST0xFX1VTRVIiLCJleHAiOjE1MjQwODcyMzJ9.MUv5RgI9LxQyrrCfjfX8HR2-XiQmz4vjLqH7V_0Du7VFLC0WrK_y3FfeNoT2Nj_uguIK2ss7jv-LNiHuCGtz4A'};
this.http.get('http://localhost:8080/links/all', headers)
.subscribe((e) => {
console.log(e);
}, (err: HttpErrorResponse) => {
console.log(err);
});
}
}
在http.get我如何设置授权?我想使用保存在const headers 中的不记名令牌。就这样。谢谢
编辑:我忘了提到我想知道如何在这里手动设置它而不是使用拦截器,所有教程都使用拦截器,所以我无法弄清楚
【问题讨论】:
标签: javascript angular httpclient