与身体的角度$ http.delete请求 [英] Angular $http.delete request with body

查看:121
本文介绍了与身体的角度$ http.delete请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我看着这个帖子: <一href="http://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request">is实体主体允许一个HTTP DELETE请求

So I looked at this post: is an entity body allowed for an http delete request

这似乎表明,虽然这是OK上做一些概念性的水平,在实践中也未必是可行的,因为浏览器忽略它。

Which seems to indicate that while it is 'ok' to do on some conceptual level, in practice it may not be doable because browsers just ignore it.

我有一些前press.js认证的中间件,我需要打通了,我不想附上我的用户详细信息的URL PARAMS。所有的需要来认证连接这些细节的请求的主体的其他请求。

I have some express.js authentication middleware I need to get through, and I don't want to attach my user details to url params. All my other requests that need to authenticate attach these details to the body of the request.

是否有某种方式来强制呢?我看到一些其他职位,其中一些人似乎已经成功地通过一个机构,他们的删除请求。

Is there some way to force this? I saw some other posts where some people seemed to have success in passing a body with their delete request.

我正在运行的节点/帆后端。它总是记录的身体作为未定义的删除请求。请问有什么办法可以修改

I am running a node/sails back-end. It always logs the body as undefined for a delete request. Is there any way to modify

推荐答案

帆API拉对象的ID从PARAMS删除,所以我们要追加ID的URL。

The sails API pulls the id of the object to delete from the params, so we have to append the id to the url.

但是,如果我想处理删除请求前通过于一体的服务器端验证一些认证的细节,我不能只是坚持在一个对象作为删除请求的第二个参数,比如你可以用$ http.post。

But if I want to pass some authentication details in a body for server-side verification before processing the delete request, I can't just stick them in an object as the second parameter of the delete request, like you can with $http.post.

角的方法后自动分配,无论我们插入作为第二个参数请求的主体,但删除方法的

Angular's post method automatically assigns whatever we insert as a second parameter to the body of the request, but the delete method does not.

角的$ http.delete方法确实可以让我们提供一个配置对象作为第二个参数,通过它我们可以访问数据属性。这也是同样的道理后做它通过它的第二个参数。

Angular's $http.delete method does allow us to supply a config object as the second parameter, through which we can get access to the 'data' property. This is the same way post does it through it's second parameter.

因此​​,如果我们需要一个机构连接到一个删除请求,我们可以使用下面的:

So if we need to attach a body to a delete request we can use the following:

$http.delete('/api/' + objectToDelete.id, {data: {id: currentUser().id, level: currentUser().level}});

这将传递对象删除的id的URL参数,并为对象在人体内我的用户凭据。

This will pass the object to delete's id in the url parameter, and my user credentials in the body as an object.

这篇关于与身体的角度$ http.delete请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆