Ruby rest-client文件作为具有基本身份验证的多部分表单数据上载 [英] Ruby rest-client file upload as multipart form data with basic authenticaion
本文介绍了Ruby rest-client文件作为具有基本身份验证的多部分表单数据上载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我理解如何使用Ruby的 rest-client
I understand how to make an http request using basic authentication with Ruby's rest-client
response = RestClient::Request.new(:method => :get, :url => @base_url + path, :user => @sid, :password => @token).execute
以及如何将文件作为多部分表单发布数据
and how to post a file as multipart form data
RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb')
但是我似乎无法弄清楚如何将两者结合起来以便将文件发布到需要基本身份验证的服务器。有谁知道创建此请求的最佳方法是什么?
but I can't seem to figure out how to combine the two in order to post a file to a server which requires basic authentication. Does anyone know what is the best way to create this request?
推荐答案
如何使用 RestClient: :Payload
with RestClient :: Request
...
例如:
How about using a RestClient::Payload
with RestClient::Request
...
For an example:
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文件作为具有基本身份验证的多部分表单数据上载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文