nodejs解析xml格式请求


一般的项目采用的bodyParser对请求包进行解析,默认支持

application/jsonapplication/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();
});

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM