发送请求体上$资源 [英] Send Request Body on $resource
问题描述
,我要为$资源上角API 一看,我没有找到某种方式来发送一个请求体
来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方法,如<一个href=\"http://stackoverflow.com/questions/12190166/angularjs-any-way-for-http-post-to-send-request-parameters-instead-of-json\">here,因此,它是也可以用做 $资源
?
I know this is possible using $http approach, like here, so, is it also possible to do using $resource
?
显然,这是 $资源
选项。
动作 - {string}里 - 操作的名称。该名称将成为您的资源对象的方法的名称。
action – {string} – The name of action. This name becomes the name of the method on your resource object.
法 - {string}里 - HTTP请求
方法。有效的方法是:GET,POST,PUT,DELETE和JSONP
method – {string} – HTTP request method. Valid methods are: GET, POST, PUT, DELETE, and JSONP
PARAMS -
{对象=} - 这个动作组可选pre绑定的参数
params – {object=} – Optional set of pre-bound parameters for this action.
IsArray的 - {布尔=} - 如果为真,那么这个返回的对象
行动是一个数组,见收益部分。
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.
推荐答案
只要行动支持体的消息(如POST,而不是GET),你可以传递一个数据参数到资源的操作方法,这将在请求的主体被发送:
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/
这篇关于发送请求体上$资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!