node.js - express3 js req.body is undefined -


i using express2.js when using req.body undefined or empty {}:

exports.post = function (req: express3.request, res: express3.response) {     console.log(req.body);     }); 

i have following configurations:

app.use(express.bodyparser()); app.use(app.router);  app.post('/getuser', routes.getuserprofile.post); 

the request body in xml , checked request header correct.

i missed part had xml. guess req.body doesn't parse default.

if using express 2.x perhaps this solution @davidkrisch adequate (copied below)

// script requires express 2.4.2 // echoes xml body in request response // // run script so: // curl -v -x post -h 'content-type: application/xml' -d '<hello>world</hello>' http://localhost:3000 var express = require('express'),     app = express.createserver();  express.bodyparser.parse['application/xml'] = function(data) {     return data; };  app.configure(function() {     app.use(express.bodyparser()); });   app.post('/', function(req, res){     res.contenttype('application/xml');     res.send(req.body, 200); });  app.listen(3000); 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -