Angular 6 - httpClient passing basic auth in httpOptions

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

    httpClient passing basic auth in httpOptions is different in Angular 6

    let httpHeaders= new HttpHeaders();
    httpHeaders.append('Content-Type', 'application/json');
    httpHeaders.append("Authorization", "Basic " + btoa("username:password"));
    
    const httpOptions = {
      headers: httpHeaders
    };
    
    update(id, title, content) {
        const updateData = { id: id, title: title, content: content };
          return this.http.put(`http://myurl/${id}`, updateData, httpOptions);
      }
    

提交回复
热议问题