1 2 3 4 5 6 7 8 9 10 11 12 13 14 | var express = require( 'express' ), app = express(), port = 8080; app.configure( function (){ app.use(express.bodyParser()); }); app.post( '/' , function (req, res){ console.log(req.body.); res.send({ status: 'SUCCESS' }); }) app.listen(port); |
위와 같은 코드로 샘플을 만들고 json을 post data로 넘겨
서버에서 log로 찍어보려 했지만 아래와 같이 undefined로 나타나더라.. 아니 왜?
한참 삽질하면서 검색하던 중에 content-type이라는 녀석이 눈에 들어온다..
그렇다 node.js 의 json data를 서버에 요청할 경우 header에 Content-Type: application/json 을 담아 요청을 했어야 했다.
별것 아닌것 같지만.. 괜한 시간 뺏길 수가 있다.