Rob*_*bin 11 ruby post http basic-authentication rest-client
我理解如何使用Ruby的rest-client使用基本身份验证来创建http请求
response = RestClient::Request.new(:method => :get, :url => @base_url + path, :user => @sid, :password => @token).execute
Run Code Online (Sandbox Code Playgroud)
以及如何将文件作为多部分表单数据发布
RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb')
Run Code Online (Sandbox Code Playgroud)
但我似乎无法弄清楚如何将两者结合起来将文件发布到需要基本身份验证的服务器.有谁知道创建此请求的最佳方法是什么?
rob*_*tus 24
如何使用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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15079 次 |
| 最近记录: |