【发布时间】:2012-09-28 02:35:39
【问题描述】:
我正在尝试使用遏制进行 HTTP PATCH。查看代码,似乎没有为此公开的方法。有什么办法可以使用遏制来做补丁?如果没有,Ruby 中还有哪些其他库或方法可以完成此任务?
【问题讨论】:
我正在尝试使用遏制进行 HTTP PATCH。查看代码,似乎没有为此公开的方法。有什么办法可以使用遏制来做补丁?如果没有,Ruby 中还有哪些其他库或方法可以完成此任务?
【问题讨论】:
使用最新版本 (v0.8.1) PATCH 受支持,即使它在 Curl::Easy 接口中未明确提供(请参阅 lib/curl/easy.rb)。
可以找到快捷方式here:
# 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)
【讨论】: