嗨,我正在为后端和 Angular 5 应用程序作为客户端开发 django rest 框架。我需要在每个请求中向服务器发送 JWT 令牌和 Content-Type 如何在请求标头中设置“jsonwebtoken”和“content-type”? ?? 看起来 RequestOptions 和 Header 在 Angular 5 中已被弃用任何解决方案???
import {Injectable} from '@angular/core';
import {Headers, RequestOptions} from '@angular/http'
import {HttpClient} from "@angular/common/http";
import 'rxjs/add/operator/map'
@Injectable()
export class UserService {
private options;
constructor(private http: HttpClient) {
const token = localStorage.getItem('theuser');
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Bearer' + ' ' + token)
this.options = new RequestOptions({headers: headers});
console.log(this.options)
}
userInfo() {
return this.http.get<any>("http://localhost:8000/user-detail/",this.options)
}
}