如何在ruby net / http中发送multipart / form-data文件以及其他表单参数?

时间:2015-04-29 11:13:17

标签: ruby multipartform-data net-http

我想使用内容类型为function y = Switch(SOC,Input,Launch,Charge,A) %#codegen y = A; if ((Launch == 1), (SOC ~= Input)) y = Charge; else y = A; end POST 方法以及其他表单参数上传文件。我已尝试使用此代码,但我收到了错误。

multipart/form-data

错误:

require 'net/http/post/multipart'

url = URI.parse('https:action/upload-v1/file')
File.open("rough.txt") do |text|
  req = Net::HTTP::Post::Multipart.new url.path,
    "file" => UploadIO.new(text, "text/plain", "rough.txt")

    req.basic_auth 'nikhil', 'Lee'

    req.verify_mode = OpenSSL::SSL::VERIFY_NONE
    req.use_ssl = true
    req.set_form_data('deviceId' => '2366', 'checksum' => '132654798', 'fileSize' => '1260', 'fileType' => 'configuration', 'compressionType' => 'Z')
  res = Net::HTTP.start(url.host, url.port) do |http|
    response = http.request(req)
    puts response.body

  end
end

0 个答案:

没有答案