Angular 4 Http POST not working

前端 未结 4 1796
天命终不由人
天命终不由人 2021-02-09 14:19

I hope everyone is doing great. I\'ve recently started working with angular 4.4, i\'ve been trying to post data to my api server, but unfortunately it\'s not working. I\'ve spen

4条回答
  •  灰色年华
    2021-02-09 14:53

    have you tried passing headers as the third argument in the post menthod:

    this.http.post('http://myapiserver.com', JSON.stringify({name: 'Adam Smith'}), { headers: new Headers({ 'Content-Type': 'application/json' }) }).subscribe(
        res => {
            const response = res.text();
        }
    );
    

    make sure you import Headers from @angular/http

提交回复
热议问题