how to set headers to application/json in angular2

前端 未结 5 1153
难免孤独
难免孤独 2021-01-17 03:00

I am trying to send HTTP post request in Angular2 but not able to set headers to content type application JSON.

My code is:

login(url,postdata)
{
            


        
5条回答
  •  走了就别回头了
    2021-01-17 03:44

    change _http.post parameters :

    login(url,postdata) {
        var headers = new Headers({'Content-Type': 'application/json'});
        return this._http.post(url,postdata,{headers:headers})
                    .map(res => res.json())    
    }
    

提交回复
热议问题