问题请求http标题角4

时间:2017-08-10 17:44:33

标签: angular typescript

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;
        });
}

不发送所有标头。现在它发送授权标题但跳过其他标题

1 个答案:

答案 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(...);