这是我的 Angular http请求,当调用deleteEmployee函数时,它会发出删除请求: 单击事件时调用此函数:
$scope.deleteEmployee=function(index){
$http({
method:'DELETE',
url:'/delete',
data:{
"ndx":"abc"
}
}).then((response)=>{
console.log(response);
})
}
这是我的 server.js 文件
var http=require('http');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/',express.static(__dirname));
app.delete('/delete',function(req,res){
console.log(req.body);
})
app.listen(8888,()=>{
console.log('Server Started');
})
在 console.log(req.body) 上,它显示为空,即 {}。
最佳答案
来自https://www.rfc-editor.org/rfc/rfc7231#section-4.3.5 :
A payload within a DELETE request message has no defined semantics; sending a payload body on a DELETE request might cause some existing implementations to reject the request.
基本上,DELETE 请求不能有正文。
关于angularjs - Nodejs 中的 req.body 为空 :{}?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42950644/