curl json通过终端向rails应用程序发布请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5658510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
curl json post request via terminal to a rails app
提问by chris sun
I'm trying to create a user on my rails app with a curl command from os x terminal. No matter how I format the data, the app returns a responses that non of my validations have passed.
我正在尝试使用来自 os x 终端的 curl 命令在我的 rails 应用程序上创建一个用户。无论我如何格式化数据,应用程序都会返回一个响应,我的验证都没有通过。
curl http://localhost:3000/api/1/users.json -i -X POST -d {"user":{"first_name":"firstname","last_name":"lastname","email":"[email protected]","password":"app123","password_confirmation":"app123"}}"
I've tried every variation. I've tried using [] brackets, I've tried user={data..} and nothing seems to work. Any ideas?
我已经尝试了所有变体。我试过使用 [] 括号,我试过 user={data..} ,但似乎没有任何效果。有任何想法吗?
回答by Bob
First off, there is an extraneous " at the end of your command.
首先,您的命令末尾有一个无关紧要的“。
Try this
尝试这个
curl -v \
-H "Accept: application/json" \
-H "Content-type: application/json" \
-X POST \
-d ' {"user":{"first_name":"firstname","last_name":"lastname","email":"[email protected]","password":"app123","password_confirmation":"app123"}}' \
http://localhost:3000/api/1/users

