Restangular - PUT request payload is being sent as

2019-08-10 08:55发布

问题:

I'm using rectangular and have something like this:

stuffResource = parentResource
          .one(resources.category, $scope.stuff.category)
          .one(resources.stuff, $scope.stuff.id)
          .put($scope.stuff);

Now, when the request is sent, my "stuff" object is being sent in the query string instead of the body!

What I'm I doing wrong here?

回答1:

What you want to do here is use customPUT() instead of the normal put().

stuffResource = parentResource
    .one(resources.category, $scope.stuff.category)
    .one(resources.stuff, $scope.stuff.id)
    .customPUT($scope.stuff);

From the docs

  • put([queryParams, headers]): Does a put to the current element

  • customPUT([elem, path, params, headers]): Does a PUT to the specific path. Optionally you can set params and headers and elem. Elem is the element to post. If it's not set, it's assumed that it's the element itself from which you're calling this function.