通过终端curl json post请求到rails应用程序

chr*_*sun 109 macos terminal json curl ruby-on-rails-3

我正在尝试使用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@email.com","password":"app123","password_confirmation":"app123"}}"
Run Code Online (Sandbox Code Playgroud)

我尝试了各种变化.我尝试使用[]括号,我尝试过user = {data ..},似乎没有任何效果.有任何想法吗?

Bob*_*Bob 225

首先,在你的命令结束时有一个无关紧要的东西.

试试这个

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"user":{"first_name":"firstname","last_name":"lastname","email":"email@email.com","password":"app123","password_confirmation":"app123"}}'  http://localhost:3000/api/1/users
Run Code Online (Sandbox Code Playgroud)

  • 认为您也可以删除-X POST,因为您使用-d (2认同)