【发布时间】:2016-03-19 22:49:15
【问题描述】:
代码如下,htis是使用express框架的node.js:
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Expressxx' });
});
router.post('/', function(req, res, next) {
var body = '';
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function() {
console.log(body);
});
/* res.send('Got the Post'); */
res.set('Content-Type', 'text/plain');
res.send('this is the body' + body);
res.end();
});
module.exports = router;
当我执行 console.log(body);我看到了预期的数据,但在客户端我看到的只是“这是身体”。似乎 res.send 无法读取正文 obj?
谢谢....
【问题讨论】: