Ruby send JSON request

后端 未结 10 1348
后悔当初
后悔当初 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条回答
  •  旧时难觅i
    2020-11-28 21:22

    A simple json POST request example for those that need it even simpler than what Tom is linking to:

    require 'net/http'
    
    uri = URI.parse("http://www.example.com/search.json")
    response = Net::HTTP.post_form(uri, {"search" => "Berlin"})
    

提交回复
热议问题