Angular 8:无法设置标题

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

我想从组件调用服务:

getToken() {
  const httpOptions = {headers: new HttpHeaders({ 'Authorization': 'Basic c3ByaW5nLXNlY3VyaXR5LW9hdXRoMi1yZWFkLXdyaXRlLWNsaWVudDpzcHJpbmctc2VjdXJpdHktb2F1dGgyLXJlYWQtd3JpdGUtY2xpZW50LXBhc3N3b3JkMTIzNA==' })};
  return this.http.post(this.rootUrl + "oauth/token?client_id=spring-security-oauth2-read-write-client&password=root1234&[email protected]&grant_type=password", httpOptions);
}

通话未显示Authorization,请检查下图:

enter image description here

angular
1个回答
0
投票

您正在将标头作为请求正文发送。

您需要将其作为第三个参数传递给通话:

this.http.post(url, null, httpOptions)
© www.soinside.com 2019 - 2024. All rights reserved.