zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[Angular] Http Custom Headers and RequestOptions

AngularHTTP and Custom headers
2023-09-14 08:59:18 时间
  updatePassenger(passenger: Passenger): Observable<Passenger> {
    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));