【发布时间】:2018-05-30 14:04:37
【问题描述】:
我正在从 Http 迁移到 HttpClient 我习惯将一些 headers 添加到我的 http 请求中,如下所示:
import { RequestOptions, Request, RequestMethod, Headers } from '@angular/http';
this.pass = btoa(cuid + ': ');
this.pass = "Basic " + this.pass;
this.header = new Headers();
this.header.set("Authorization", this.pass);
let options = new RequestOptions({
headers: this.header
});
return this.http.post(myServiceUrl, {}, options)
现在迁移到 httpClient 时,我已经尝试过:
import {HttpClient, HttpHeaders} from '@angular/common/http';
const header = new HttpHeaders();
const pass = 'Basic ' + btoa(cuid + ': ');
header.set('Authorization', pass);
const options = ({
headers: header
});
return this.httpClient.post(myServiceUrl, {}, options);
但是你可以看到 ivent 找到了 RequestOptions 的等价物,并且整个处理都没有添加相同的标题。
建议??
【问题讨论】:
-
HttpParams是新版本,从同一个地方导入
标签: angular typescript angular-http angular-httpclient