0

我想知道 $http 是否可以使用 LINK/UNLINK 方法(如 POST、GET、PUT、PATCH ..)向服务器发送 ajax 请求。我已经在 AngularJS 文档中进行了搜索,只找到了以下可用方法列表:

  • $http.get
  • $http.head
  • $http.post
  • $http.put
  • $http.delete
  • $http.jsonp
  • $http.补丁

AngularJs $http 文档

当您只想在资源之间建立关系时,LINK 方法非常有用,如果缺少它真的很可惜。如果有人知道如何做这个请求,可以给我一个例子吗?

LINK/UNLINK 方法示例:

There exists a broad range of possible use cases for the LINK and UNLINK methods. The examples that follow illustrate a subset of those cases.

Example 1: Creating two separate links between an image and the profiles of two people associated with the image:

  LINK /images/my_dog.jpg HTTP/1.1
  Host: example.org
  Link: <http://example.com/profiles/joe>; rel="tag"
  Link: <http://example.com/profiles/sally>; rel="tag"

Example 2: Removing an existing Link relationship between two resources:

  UNLINK /images/my_dog.jpg HTTP/1.1
  Host: example.org
  Link: <http://example.com/profiles/sally>; rel="tag"

以下是有关 LINK 方法的一些文档:

http://www.w3.org/Protocols/HTTP/Methods/Link.html

http://tools.ietf.org/id/draft-snell-link-method-01.html#RFC5988

4

2 回答 2

0

您也可以$http不使用那些简短的方法,这可能会起作用,如果不检查是否有带有OPTIONS方法的请求

$http({method: 'LINK', url: '/someUrl'}).
  success(function(response){
    //do something fancy
  })
于 2014-08-20T22:12:56.203 回答
0

不,抱歉,默认情况下 AngularJS 不提供任何使用 LINK 的请求。

所以你有选择:

  • 改变动词。
  • 在您和目标服务器之间放置另一台服务器以进行代理。
  • 使用允许使用 LINK 的 restangular。
于 2017-08-17T08:00:43.177 回答