How to correctly set Http Request Header in Angular 2

前端 未结 7 1979
终归单人心
终归单人心 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 06:57

    Your parameter for the request options in http.put() should actually be of type RequestOptions. Try something like this:

    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    headers.append('authentication', `${student.token}`);
    
    let options = new RequestOptions({ headers: headers });
    return this.http
        .put(url, JSON.stringify(student), options)
    

提交回复
热议问题