register(
email: string,
password: string,
firstName: string,
lastName: string,
): Observable<any> {
const headers = new HttpHeaders()
.set('Authorization', "Basic " + btoa(email + ":" + password + ":" + firstName + ":" + lastName));
headers.set('X-LSM-AccessToken', environment.DomainApiKeyHeaderName+':'+environment.salt);
headers.set(environment.DomainApiKeyHeaderName, environment.DomainApiKey);
let body = JSON.parse(localStorage.getItem('currentUser'));
return this.http.post(
environment.Domain + '/api/v1/Authentication/register',
body,
{ headers }
)
.map(data => {
return data;
});
}
不发送所有标头。现在它发送授权标题但跳过其他标题
答案 0 :(得分:4)
HttpHeaders是不可变的。它的set()方法返回一个新的Header值。但是你忽略了结果。将您的代码更改为
const headers = new HttpHeaders().set(...)
.set(...)
.set(...);
或
let headers = new HttpHeaders();
headers = headers.set(...);
headers = headers.set(...);
headers = headers.set(...);