为什么我在AngularJs中的http.delete时无法传递参数?

时间:2022-03-13 22:55:32

I have function to call http.delete and pass a parameter flag:

我有调用http.delete并传递参数标志的函数:

function softDeleteDatasource(datasourceId,flag) {
            var url = baseUrl + datasourceId;
            return $http.delete(url, {'currentFieldSetFlag':flag});
        }

Then I assume I can get the req.body with following code. However, I always get undefined in the console.log. I used exactly same code in http.post and it works fine when passing parameter.

然后我假设我可以使用以下代码获取req.body。但是,我总是在console.log中未定义。我在http.post中使用完全相同的代码,它在传递参数时工作正常。

var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
router.delete('/:datasourceId', jsonParser, function(req, res) {
   console.log(req.body.currentFieldSetFlag);
}

I am confused why the same code can not pass parameter in http.delete? anyone know how to pass it?

我很困惑为什么相同的代码不能在http.delete中传递参数?谁知道怎么通过呢?

1 个解决方案

#1


4  

The HTTP spec allows for bodies on DELETEs, but some clients do not send them and some proxies/servers will strip/ignore them if present. This ought to work to pass it as a querystring parameter:

HTTP规范允许DELETE的主体,但是一些客户端不发送它们,并且一些代理/服务器将剥离/忽略它们(如果存在)。这应该将它作为查询字符串参数传递:

return $http.delete(url, {params: {'currentFieldSetFlag':flag}});

#1


4  

The HTTP spec allows for bodies on DELETEs, but some clients do not send them and some proxies/servers will strip/ignore them if present. This ought to work to pass it as a querystring parameter:

HTTP规范允许DELETE的主体,但是一些客户端不发送它们,并且一些代理/服务器将剥离/忽略它们(如果存在)。这应该将它作为查询字符串参数传递:

return $http.delete(url, {params: {'currentFieldSetFlag':flag}});