Angular で JSON を POST で送信しようとすると空になる
はじめに
環境
- Angular 4.3.5
公式ドキュメントのコード
- このとおりだと Body が空になる
const body = {name: 'Brad'}; http .post('/api/developers/add', body) // See below - subscribe() is still necessary when using post(). .subscribe(...);
対策したコード
- JSON.stringify すると正常にデータが POST できる
const body = JSON.stringify({name: 'Brad'}); http .post('/api/developers/add', body) // See below - subscribe() is still necessary when using post(). .subscribe(...);