angularjs - Nodejs 中的 req.body 为空 :{}?

标签 angularjs node.js

这是我的 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/

相关文章:

javascript - 使用 ui.router AngularJs 进行路由

javascript - 参数 'meetupsController' 不是函数,出现未定义错误

sql-server - [连接错误: Failed to connect to IP in 15000ms]

mysql - 在ElectronJS Production App中确保数据库连接安全吗?

javascript - 如何将 npm 用于前端依赖项?

node.js - NVM 和 Node.js - 推荐给所有用户安装

angularjs - Keycloak + AngularJS : persist URL hash fragments after login redirect url

angularjs - 您如何检测 AngularJS 中的 HTML 渲染何时完成

node.js - 具有 2 条腿的 oauth 的 Google Drive file.update 返回正常,但无法按预期工作

css - 将 html 表导出为 pdf,其所有 css 完好无损