How to receive a JSON object with Rack

后端 未结 3 719
臣服心动
臣服心动 2021-01-02 23:35

I have a very simple Ruby Rack server, like:

app = Proc.new do |env| 
  req = Rack::Request.new(env).params
  p req.inspect 
  [200, { \'Content-Type\' =>         


        
3条回答
  •  旧时难觅i
    2021-01-03 00:05

    env['rack.input'].gets
    

    This worked for me. I found that using curl or wget to test POST requests against a Rack (v1.4.1) server required using this code as a fallback to get the request body. POST requests out in the wild (e.g. GitHub WebHooks) didn't have this same problem.

提交回复
热议问题