节点服务器接收XmlHttpRequest

我使用下面的代码发送会话描述(小JSON代码 – http://www.ietf.org/rfc/rfc2327.txt )。

function sendMessage(message) { var msgString = JSON.stringify(message); console.log('C->S: ' + msgString); path = '/message?r=67987409' + '&u=57188688'; var xhr = new XMLHttpRequest(); xhr.open('POST', path, true); xhr.send(msgString); } 

我不知道如何去解决我的Node.js服务器上的JSON。

这是一个可以在node.js中处理POST请求的代码。

 var http = require('http'); var server = http.createServer(function (request, response) { if (request.method == 'POST') { var body = ''; request.on('data', function (data) { body += data; }); request.on('end', function () { var POST = JSON.parse(body); // POST is the post data }); } }); server.listen(80); 

希望这可以帮到你。