har*_*ung 2 json xmlhttprequest node.js webrtc
我正在使用以下代码发送会话描述(微小的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);
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何在我的Node.js服务器上检索JSON.
这是一个可以处理POSTnode.js中的请求的代码.
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);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮到你.
| 归档时间: |
|
| 查看次数: |
1855 次 |
| 最近记录: |