I am trying to send a file via a HTTP PUT
request. Curl
allows this like:
http://curl.haxx.se/docs/httpscripting.html#PUT
What's the correct way of doing this with Typheous?
FWIW,我认为这是对该问题的完整(但不一定是最短)答案。
Curl 允许上传带有 PUT 的文件;调用是:
$ curl --upload-file filename url
其中 url 可能类似于:
http://someurl/script.php?var=value&anothervar=val&...
Typhoeus 提供了相同的功能,但传递 url、params 及其值以及文件正文的正确方法隐藏在 ethon 文档中:
request = Typhoeus::Request.new(
url, :method => :put, :params => params_hash,
:body => File.open(filename) { |io| io.read })
使用请求对象获取响应等。
你不可能看起来很努力:
例子:
提出 put 请求。
Typhoeus.put("www.example.com")
参数:
base_url (String) — The url to request. options (options) (defaults to: {}) — The options.
选项哈希(选项):
:params (Hash) — Params hash which is attached to the base_url. :body (Hash) — Body hash which becomes a PUT request body.
http://rubydoc.info/github/typhoeus/typhoeus/Typhoeus/Request/Actions#put-instance_method