我了解如何通过 Ruby 的 rest-client 使用基本身份验证发出 http 请求
response = RestClient::Request.new(:method => :get, :url => @base_url + path, :user => @sid, :password => @token).execute
以及如何将文件作为多部分表单数据发布
RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb')
但我似乎无法弄清楚如何将两者结合起来以便将文件发布到需要基本身份验证的服务器。有谁知道创建此请求的最佳方式是什么?
最佳答案
如何使用 RestClient::Payload
和 RestClient::Request
...
例如:
request = RestClient::Request.new(
:method => :post,
:url => '/data',
:user => @sid,
:password => @token,
:payload => {
:multipart => true,
:file => File.new("/path/to/image.jpg", 'rb')
})
response = request.execute
关于Ruby rest-client 文件上传为具有基本身份验证的多部分表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11388090/