How to correctly set Http Request Header in Angular 2

前端 未结 7 1929
终归单人心
终归单人心 2020-11-27 06:10

I have an Ionic 2 application using Angular 2, which is sending an Http PUT to a ASP.NET Core API server. Here\'s the method I\'m using to send the request:



        
相关标签:
7条回答
  • 2020-11-27 07:16

    The simpler and current approach for adding header to a single request is:

    // Step 1

    const yourHeader: HttpHeaders = new HttpHeaders({
        Authorization: 'Bearer JWT-token'
    });
    

    // POST request

    this.http.post(url, body, { headers: yourHeader });
    

    // GET request

    this.http.get(url, { headers: yourHeader });
    
    0 讨论(0)
提交回复
热议问题