How to pass parameters in headers - Headers Angular 4?

1

Angular 4

Greetings community, I'm trying to pass some parameters by the headers in a post request but it generates an error, it tells me that it is not sending the parameters in the headers, does anyone know what I'm doing wrong?

registerHome(user_to_registerHome){
    let params = JSON.stringify(user_to_registerHome);
    let headers = new Headers({'Content-Type': 'application/json; charset=utf-8;'},{'token':this.getToken});

    return this._http.post(this.url+'consolaseguridad-service/createUser', params, {headers: headers})
                      .map(res => res.json());
  }
    
asked by Elberth Agreda 03.08.2017 в 15:37
source

2 answers

1

Expanding the answer of @Findelias, the header token does not exist, the thing should be like this:

let headers = new Headers();
headers.append('Content-Type', 'application/json', 'charset=utf-8;')
headers.append('Authorization', this.getToken);

return this._http.post(this.url+'consolaseguridad-service/createUser', params,)
                      .map(res => res.json());
    
answered by 04.08.2017 / 13:01
source
0

Try this.

let headers = new Headers();
headers.append('Content-Type', 'application/json', 'charset=utf-8;')

return this._http.post(this.url+'consolaseguridad-service/createUser', params,)
                      .map(res => res.json());

If you get any other mistake, comment it and see it.

    
answered by 04.08.2017 в 11:53