Adding a HTTP header to the Angular HttpClient doesn't send the header, why?

前端 未结 9 1100
孤街浪徒
孤街浪徒 2020-11-22 05:45

Here is my code:

import { HttpClient, HttpErrorResponse, HttpHeaders } from \'@angular/common/http\';
9条回答
  •  借酒劲吻你
    2020-11-22 06:25

    I was with Angular 8 and the only thing which worked for me was this:

      getCustomHeaders(): HttpHeaders {
        const headers = new HttpHeaders()
          .set('Content-Type', 'application/json')
          .set('Api-Key', 'xxx');
        return headers;
      }
    

提交回复
热议问题