我正在尝试使用承载令牌从Cloud Foundry API获取信息。通过http标头传递承载令牌时,出现403错误。看来,当我通过proxy.conf.json传递请求时,标头未得到处理。
这是我在PcfAppsService服务中拥有的东西:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class PcfAppsService {
constructor(private http: HttpClient) {}
getPcfApps(): Observable<any> {
return this.http.get<any>('/v2/apps', {
headers: new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'bearer tokenStringGoesHere'
})
});
}
}
我可以使用以下任一组件调用服务:
constructor( private pcfApps: PcfAppsService) {}
ngOnInit() {
this.pcfApps.getPcfApps().subscribe(data => {
console.log(data);
});
}
在proxy.config.json内部,我具有以下内容:
{
"/v2/apps": {
"target": "https://api.scp1syspdv.schwab.com/v2/apps",
"changeOrigin": true,
"logLevel": "debug",
"secure": false,
"pathRewrite": {
"^/v2/apps": ""
}
}
}
有没有办法解决这个问题?我想念什么吗?