Angular 6 - httpClient passing basic auth in httpOptions

前端 未结 6 1373
灰色年华
灰色年华 2020-12-08 10:48

I have a service in Angular 6 and I\'m trying to change a record but it\'s saying I\'m not authorized.

Right now I have this:

const httpOptions = {
          


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 11:48

    import { HttpClient, HttpHeaders } from '@angular/common/http';
    
    var headers = new HttpHeaders();
    
    var token = localStorage.getItem('token');
    
    headers.append('Content-Type', 'application/json');
    
    headers.append("Authorization", "Basic " + token));
    
    const httpOptions = {
      headers: headers
    };
    

提交回复
热议问题