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

发布于 2024-11-01 18:02:43 字数 491 浏览 0 评论 0原文

我正在尝试使用 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"}}"

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

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎言笑 2024-11-08 18:02:43

首先,命令末尾有一个无关的“。

试试这个

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文