0

在角 9

const headers = new HttpHeaders()
.set('Content-Type', 'application/json; charset=utf-8')
.set('Authorization', this.getToken());   
return this.httpClient.get(url,{headers:headers}).pipe(catchError(this.handleError));

无法连接 httpheaders。get post put delete call 为什么没有附加标题?

4

2 回答 2

2

这是正确的语法:

const httpOptions = new HttpHeaders({
  'Content-Type': 'application/json',
  'Authorization': this.getToken()
});
this.httpClient.get(url, httpOptions).pipe(catchError(this.handleError));
于 2020-01-17T05:20:41.407 回答
-1

你可以试试这个: -

let headers = new HttpHeaders()
headers=headers.set('Content-Type', 'application/json; charset=utf-8')
headers=headers.set('Authorization', this.getToken());   
return this.httpClient.get(url,{headers:headers}).pipe(catchError(this.handleError));

由于 httpheader 和 httpparams 本质上是不可变的,因此将其分配给返回的对象应该可以工作。

于 2020-01-05T19:07:32.710 回答