Angular 6 - httpClient passing basic auth in httpOptions

前端 未结 6 1374
灰色年华
灰色年华 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:37

    Looking at the angular.io documentation, it's pretty straightforward.

    const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type':  'application/json',
        'Authorization': 'Basic my-auth-token'
      })
    };
    

    And you can use the httpOptions constant as you did.

    For more information: https://angular.io/guide/http#adding-headers

提交回复
热议问题