zoukankan      html  css  js  c++  java
  • [Angular] Set Metadata in HTTP Headers with Angular HttpHeaders

    Besides sending (or requesting) the actual data to the server API, there’s also often the need to send further metadata that helps the server to correctly interpret our request. Such data is most often sent using HTTP headers. In this lesson we learn how to leverage Angular’s HttpClient to set such headers. Note that when you have to continuously send certain application headers to the backend, for each single HTTP call that is being made, you may be better served by placing them in an HTTP interceptor. 

    import { Injectable } from '@angular/core';
    import { Observable } from 'rxjs/Observable';
    import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
    
    @Injectable()
    export class PeopleService {
    
      constructor(private http: HttpClient) {}
    
      fetchPeople(): Observable<Object> {
        return this.http
          .get('data/people.json', {
            headers: new HttpHeaders().set('app-language', 'en')
          });
      }
    
    }
  • 相关阅读:
    QT多个UI文件加入一个项目
    【Go语言】学习资料
    MVC如何在Pipeline中接管请求的?
    ASP.NET MVC路由(5)
    C# dll 事件执行 js 回调函数
    初识Identity
    SpringMVC拦截器
    UrlRouting的理解
    ASP.NET MVC路由
    ASP.NET MVC Module
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8448884.html
Copyright © 2011-2022 走看看