[Angular] Http Custom Headers and RequestOptions

  updatePassenger(passenger: Passenger): Observable {
    let headers = new Headers({
      'Content-Type': 'application/json'
    });
    let options = new RequestOptions({
      headers: headers
    });
    return this.http
      .put(`${PASSENGER_API}/${passenger.id}`, passenger, options)
      .map((response: Response) => response.json());
  }

 

From Angular V4, there is new HttpClient module, in which HttpHeaders is an immutable api.

const headers = new HttpHeaders()
            .set("X-CustomHeader", "custom header value");

this.courses$ = this.http
    .get(
        "/courses.json",
        {headers})
    .do(console.log)
    .map(data => _.values(data));

 

你可能感兴趣的:([Angular] Http Custom Headers and RequestOptions)