通过终端发送请求到 Rails 应用程序

我试图在我的 Rails 应用程序上创建一个用户,使用来自 os x 终端的 curl 命令。无论我如何格式化数据,应用程序都会返回一个未经我验证的响应。

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"}}"

我尝试了所有的变化。我尝试了使用[]括号,我尝试了用户 = { data. . } ,但似乎没有什么效果。有什么想法吗?

90974 次浏览

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@email.com","password":"app123","password_confirmation":"app123"}}' \
http://localhost:3000/api/1/users