Created
March 26, 2012 23:13
-
-
Save davidkrisch/2210498 to your computer and use it in GitHub Desktop.
Express-Node: Accepting POST with Content-Type: application/xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This script requires Express 2.4.2 | |
// It echoes the xml body in the request to the response | |
// | |
// Run this script like 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/11625519/how-to-access-the-request-body-when-posting-using-node-js-and-express
"Express's bodyParser only parses the incoming data, if the content-type is set to either of the following:
In all other cases, it does not even bother reading the data."
this anyBodyParser will always ready the body and put the content into req.rawBody