Ruby https POST with headers

后端 未结 5 824
花落未央
花落未央 2020-12-08 02:38

How can I make a Https post with a header in Ruby with a json?

I have tried:

uri = URI.parse(\"https://...\")
    https = Net::HTTP.new(uri.host,uri.         


        
5条回答
  •  感动是毒
    2020-12-08 03:21

    Its working, you can pass data and header like this:

    header = {header part}
    data = {"a"=> "123"}
    uri = URI.parse("https://anyurl.com")
    https = Net::HTTP.new(uri.host,uri.port)
    https.use_ssl = true
    req = Net::HTTP::Post.new(uri.path, header)
    req.body = data.to_json
    res = https.request(req)
    
    puts "Response #{res.code} #{res.message}: #{res.body}"
    

提交回复
热议问题