angularjs $ http可以与LINK方法/动​​词一起使用吗?

时间:2014-08-20 22:04:46

标签: javascript ajax angularjs http http-method

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

  • $ http.get
  • $ http.head
  • $ http.post
  • $ http.put
  • $ http.delete
  • $ http.jsonp
  • $ http.patch

AngularJs $http doc

当您想要仅在资源之间建立关系时,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

2 个答案:

答案 0 :(得分:0)

如果不使用$http方法检查是否存在请求

,您也可以使用OPTIONS而不使用这些简短方法,这可能会有效
$http({method: 'LINK', url: '/someUrl'}).
  success(function(response){
    //do something fancy
  })

答案 1 :(得分:0)

不,抱歉,默认情况下,AngularJS无论如何都不提供LINK请求。

所以你有选择:

  • 更改动词。
  • 在您和目标服务器之间放置另一台服务器以执行代理。
  • 使用restangular,允许使用LINK。