Restangular - PUT请求负载被作为查询字符串参数发送

Restangular - PUT request payload is being sent as query string parameters

本文关键字:字符串 查询 参数 PUT 请求 负载 Restangular      更新时间:2023-09-26

我用的是矩形,像这样:

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

现在,当请求被发送时,我的"stuff"对象是在查询字符串中发送的,而不是在正文中!

我做错了什么?

这里要做的是使用customPUT()而不是普通的put()。

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

从docs

  • put([queryParams, headers]):对当前元素执行put操作

  • customPUT([elem, path, params, headers]):对特定路径执行PUT操作。你可以选择设置参数、头和元素。Elem是要发布的元素。