Ruby POST multipart/form-data 结果 302 Found

问题描述

我正在尝试将 csv 文件上传到我的端点。我尝试这样做并导致 302 Found。 尝试了此处提到的其他解决方案:Multipart POST Ruby HTTPS 但结果相同。

使用 net/http 的第一个选项

Close()

使用 'rest-client' 的第二个选项和 https://github.com/rest-client/rest-client

中提到的步骤
url = URI('https://abcd.com/test/upload')

out_file = '/Users/username/Downloads/test.csv'

https = Net::HTTP.new(url.host,url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["username"] = '[email protected]'
request["password"] = 'test2345'

form_data = [['file',File.open(out_file)]]
request.content_type = 'multipart/form-data'
request.set_form form_data,'multipart/form-data'
response = https.request(request)
puts "Response from CRA is #{response.read_body}"

result:
 #<Net::HTTPFound 302 Found readbody=true>
out_file = '/Users/username/Downloads/test.csv'
url = "https://abcd.com/test/upload"

begin
    response = RestClient.post(url,:file => File.new(out_file,'rb'),:headers => { "username": "[email protected]","password": "test2345"}) 
rescue RestClient::ExceptionWithResponse => err
end

result:
[319] pry(main)> err
=> #<RestClient::Found: 302 Found>
[320] pry(main)> err.response
=> <RestClient::Response 302 "<html><head...">
[321] pry(main)> err.response.follow_redirection
IOError: closed stream
[322] pry(main)>

谁能帮我理解我做错了什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)