学习表达并面对问题。在我创建模块体解析器之后开始不起作用。所有请求都是合并的,但数据不会解析。
let express = require('express');
let bp = require('body-parser');
let dishRouter = require('./dishRouter');
let app = express();
let hostname = 'localhost';
let port = 8080;
dishRouter.use(bp.json()); //don't work
app.use('/dishes', dishRouter);
app.use(express.static(__dirname + '/public'));
app.listen(port, hostname, function(){
console.log(__dirname);
console.log(`Server has running at http://${hostname}:${port}`);
});
//我的dishRouter模块
let express = require('express');
let router = express.Router();
router.route('/')
.all(function(req, res, next){
res.writeHead(200, {'Content-type': 'text/plain'});
next();
})
.get(function(req, res, next){
res.end('We will dish for you');
})
.post(function(req, res, next){
res.end('Will add the dish:' + req.body.name + ' with details: ' + req.body.description);
})
.delete(function(req, res, next){
res.end('Deleting all dishes');
});
module.exports = router;
答案 0 :(得分:0)
如本例所示,您在休息后错过了发送:
using (var sr = new StreamReader(endpointResponse.GetResponseStream())) {
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var jsonObject = serializer.DeserializeObject(sr.ReadToEnd());
return Json(jsonObject, JsonRequestBehavior.AllowGet);
}