Ruby send JSON request

后端 未结 10 1357
后悔当初
后悔当初 2020-11-28 20:37

How do I send a JSON request in ruby? I have a JSON object but I dont think I can just do .send. Do I have to have javascript send the form?

Or can I us

10条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 21:21

    data = {a: {b: [1, 2]}}.to_json
    uri = URI 'https://myapp.com/api/v1/resource'
    https = Net::HTTP.new uri.host, uri.port
    https.use_ssl = true
    https.post2 uri.path, data, 'Content-Type' => 'application/json'
    

提交回复
热议问题