我正在使用expressjs和body-parser中间件.
这就是我发起它的方式:
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
Run Code Online (Sandbox Code Playgroud)
从客户端我发送DELETE请求,当我尝试从服务器端提取它时,我得到一个空对象:
app.delete('/', function(req, res) {
console.log(util.inspect(req.body)); //outputs {}
//some more code
});
Run Code Online (Sandbox Code Playgroud)
但是当我发送POST时,我得到了我需要的东西:
app.post('/delete', function(req, res) {
console.log(util.inspect(req.body)); //outputs { mid: 'ffw1aNh2' }
//some more code
});
Run Code Online (Sandbox Code Playgroud)
值得注意的是,我没有在客户端更改任何内容(angularjs),但方法和url以及firefox网络调试器显示在两种情况下发送的数据.
这里缺少什么?为什么我在删除方法上获得一个空体对象?