How do I POST JSON in Angular 2?

后端 未结 3 1373
孤街浪徒
孤街浪徒 2020-12-24 03:00

I don\'t understand what I am doing wrong, my server returns \"undefined\" when I try to get the json.

POST(url, data) {
        var headers = new Headers(),         


        
3条回答
  •  误落风尘
    2020-12-24 03:46

    The header should be

    'Content-Type': 'application/json'
    

    and

     body: data
    

    should be

     body: JSON.stringify(data);
    

提交回复
热议问题