express 是基于 connect 开发的,使用 bodyParser 对请求的包体进行解析,默认支持:application/json
, application/x-www-form-urlencoded
, 以及 multipart/form-data
。 也就是说不支持对 XML 形式的包体进行解析。
但是以 XML 格式作为接口数据交换还是有人在用,比如 Microsoft 的 Bing Translator HTTP API,以及腾讯微信的公众平台接口。之前用 Node.js 实现调用 Bing Translator 接口时用过 Node.js 的 xml2js 库,可以把 XML 转换成 JSON 格式以方便我们的程序进行解析。这里我们同样可以使用 xml2js 扩展 express 以使其支持 XML 形式的请求。
参考:
- https://gist.github.com/davidkrisch/2210498
- http://expressjs.com/api.html#bodyParser
- http://stackoverflow.com/questions/11002046/extracting-post-data-with-express
- https://groups.google.com/forum/?fromgroups=#!topic/express-js/6zAebaDY6ug