Ruby rest-client file upload as multipart form data with basic authenticaion

后端 未结 4 1891
不思量自难忘°
不思量自难忘° 2021-02-05 22:02

I understand how to make an http request using basic authentication with Ruby\'s rest-client

response = RestClient::Request.new(:method => :get, :url => @b         


        
4条回答
  •  半阙折子戏
    2021-02-05 22:31

    Here is an example with a file and some json data:

    require 'rest-client'
    
    payload = {
      :multipart => true,
      :file => File.new('/path/to/file', 'rb'),
      :data => {foo: {bar: true}}.to_json
          }
    
    r = RestClient.post(url, payload, :authorization => token)
    

提交回复
热议问题