app.js 中的这段代码:
var express = require('express'),
app = express(),
port = parseInt(process.env.PORT, 10) || 3000;
app.configure(function(){
app.use(express.bodyParser());
app.use(app.router);
});
app.listen(port);
app.post("/", function(req, res) {
console.log("Body: " + req.body);
res.send({ status: 'SUCCESS' });
});
跑步
PS C:\> curl -X POST -H "Content-Type:application/json" -d '{"type":"server","name":"SERVER1"}' http://localhost:3000/
结果是:
SyntaxError: Unexpected token t
at Object.parse (native)
at IncomingMessage.<anonymous (C:\temp\neo4jstest2\node_modules\express\node_modules\connect\lib\middleware\json.js
:76:27)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at _stream_readable.js:910:16
at process._tickCallback (node.js:415:13)
我已经在 Ubuntu 13.04 上测试了相同的代码,它运行良好。
在 Windows 上是否有任何差异或调整以使其正常工作?