一般的项目采用的bodyParser对请求包进行解析,默认支持
application/json
, application/x-www-form-urlencoded
, 以及 multipart/form-data。
是不支持xml格式的请求包进行解析的,可以采用 application/json 进行解析扩充
var express = require('express'), bodyParser = require('body-parser'); require('body-parser-xml')(bodyParser); var app = express(); app.use(bodyParser.xml({ xmlParseOptions: { normalize: true, // Trim whitespace inside text nodes normalizeTags: true, // Transform tags to lowercase explicitArray: false // Only put nodes in array if >1 } })); app.post('/users', function(req, res, body) { console.log(req.body); res.status(200).end(); });