在 $resource 上发送请求正文 [英] Send Request Body on $resource

查看:30
本文介绍了在 $resource 上发送请求正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了 $resource 的 Angular API,但我没有t 找到某种方法将 Request Body 发送到 RESTful 服务.

I take a look on Angular API for $resource and I didn't find some way to send a Request Body to a RESTful service.

我知道这可以使用 $http 方法实现,例如 here,那么,是否也可以使用 $resource ?

I know this is possible using $http approach, like here, so, is it also possible to do using $resource?

显然这是 $resource 的选项.

action – {string} – 动作的名称.此名称成为资源对象上方法的名称.

action – {string} – The name of action. This name becomes the name of the method on your resource object.

method – {string} – HTTP 请求方法.有效方法是:GET、POST、PUT、DELETE 和 JSONP

method – {string} – HTTP request method. Valid methods are: GET, POST, PUT, DELETE, and JSONP

参数 –{object=} – 此操作的可选预绑定参数集.

params – {object=} – Optional set of pre-bound parameters for this action.

isArray – {boolean=} – 如果为真,则返回此对象action 是一个数组,参见返回部分.

isArray – {boolean=} – If true then the returned object for this action is an array, see returns section.

目前我没有找到任何方法来发送包含 JSON 对象的请求负载.

At the moment I didn't found any way to send a request payload containing an JSON object.

推荐答案

只要 action 支持正文消息(例如 POST,但不支持 GET),您就可以向资源的 action 方法传递一个数据参数,即将在请求正文中发送:

As long as the action supports a body message (e.g. POST, but not GET), you can pass a data parameter to the action method of your resource, which will be sent in the body of the request:

yourResource.save(yourData)

示例:http://jsfiddle.net/N3NXK/1/

这篇关于在 $resource 上发送请求正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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