0

我正在尝试使用遏制做一个 HTTP PATCH。查看代码,似乎没有为此公开的方法。有什么办法可以使用遏制来做补丁?如果没有,Ruby 中还有哪些其他库或方法可以完成此任务?

4

1 回答 1

1

支持最新版本 (v0.8.1) PATCH,即使它在Curl::Easy界面中未明确提供(请参阅参考资料lib/curl/easy.rb)。

您可以在此处找到快捷方法:

# see lib/curl.rb
module Curl
  # ...
  def self.patch(url, params={}, &block)
    http :PATCH, url, postalize(params), nil, &block
  end
  # ...
end

有了它,您可以执行PATCH如下请求:

curl = Curl.patch("http://www.example.com/baz", {:foo => "bar"})

在引擎盖下,PATCH动词只是简单地传递给简单的接口,如下所示:

curl = Curl::Easy.new(url)

# `http` is a method implemented within the C extensions of curb
# see `ruby_curl_easy_perform_verb_str`. It allows to set the HTTP
# verb by calling `curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, verb)`
# and perform the request right after
curl.http(:PATCH)
于 2012-09-28T08:02:44.933 回答