我正在尝试使用httpClient发送Autherization标头,但它没有在请求中发送。
getAuthorizationHeaderClient() {
var jwt = this._cookie.get('my_authentication');
this.authHeader = new HttpHeaders();
if (jwt) {
this.authHeader.set('Authorization', 'Bearer ' + jwt);
}
return this.authHeader;
}
const req = new HttpRequest('POST',baseUrl + url, itemToPost,{
headers:this.getAuthorizationHeaderClient(),
reportProgress: true,
});
this._httpClient.request(req).subscribe(event => {
// Via this API, you get access to the raw event stream.
// Look for upload progress events.
if (event.type === HttpEventType.UploadProgress) {
// This is an upload progress event. Compute and show the % done:
const percentDone = Math.round(100 * event.loaded / event.total);
console.log(`File is ${percentDone}% uploaded.`);
} else if (event instanceof HttpResponse) {
console.log('File is completely uploaded!');
}
});