Angular JS中使用Patch方法进行HTTP请求出现问题

8
以下是我的代码:
  $http({
      url: 'https://apistage.dealsignal.com/api/v0/company_watchlists/' + wishlist_id,
      method: 'PATCH',
      params: {
          list: {
              add_company_ids: ['61737'],
              name: 'My Wishlist'
          },
          api_key: 'CtxY3Kpc7ZDL8VDfLmPt9wss'
      }
  })
      .success(function(response) {
          console.log(response);
      }).
  error(function(response) {
      console.log(response);
      return false;
  });

我在使用 Chrome 的 REST CLIENT 发送相同请求时能够正常工作,但现在却遇到了“Bad Request”错误。

2
大多数情况下,当浏览器请求失败,但在Postman或其他REST客户端中成功时,这意味着服务器中的CORS设置不正确。 - Ori Drori
2个回答

7
请参阅Angular文档。这将是数据而不是参数。
$http({
  url: 'https://apistage.dealsignal.com/api/v0/company_watchlists/' + wishlist_id,
  method: 'PATCH',
  data: {
      list: {
          add_company_ids: ['61737'],
          name: 'My Wishlist'
      },
      api_key: 'CtxY3Kpc7ZDL8VDfLmPt9wss'
  }
}).success(function(response) {
      console.log(response);
  }).
  error(function(response) {
  console.log(response);
  return false;
});

我正在尝试利用这个答案,但我的后端没有从数据参数中接收到任何内容。有什么想法吗?最初我尝试使用$resource,但是遇到了同样的问题。(http://stackoverflow.com/questions/33917898/asp-net-odata-patchvalue-received-from-angular-is-nothing) - Mike Feltman

2
我不确定,但问题可能在于参数“params”应该被命名为“data”,就像进行POST请求时一样。
希望这能有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接