我有这个卷曲电话:
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"name":"abc", "orgid":"12", "subject":"my subject"}' http://localhost:3000/mysinatraapp
post '/mysinatraapp' do
unless request.preferred_type.eql? 'text/html'
# This is not really params hash. It will be a string like "{\"name\"=>\"abc\", \"orgid\"=>\"12\", \"subject\"=>\"my subject\"}"
params = request.env["rack.input"].read
...
...
halt 400 if params.length == 0
end
# This does not work
p "hi #{params['name']}"
end
p "hi #{params['name']}"
失败,因为它不是哈希。我如何使它工作?
我的目标是将发布的 json 作为params
哈希。这样我就可以params
像往常一样使用了。