Send headers in angular http request

2

I need to send three values in my header in http request, but when I check in the browser I realize that my headers have not been sent.

I tried something like:

  trocaToken(token):Observable<any>{
    const _headers = new HttpHeaders();
    const headers = _headers.append('Content-Type', 'application/x-www-form-urlencoded');
    headers.append('token', token);
    headers.append('Authorization',  'bearer ' + token);
    return this._http.post<Usuario>(AppSettings.API_ENDPOINT + 'admin/detalhes',
    {headers: headers})
  }
    
asked by anonymous 23.07.2018 / 16:28

1 answer

0

Try this:

  trocaToken(token):Observable<any>{
     const httpOptions = {
     headers: new HttpHeaders({
        Content-Type': 'application/x-www-form-urlencoded',
        'token': token
     })
  };

  return this.http.post<Usuario>(AppSettings.API_ENDPOINT + 'admin/detalhes', undefined, httpOptions)
}
    
24.07.2018 / 11:50