curl json post请求通过终端到rails应用程序 [英] curl json post request via terminal to a rails app

查看:212
本文介绍了curl json post请求通过终端到rails应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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@email.com","password":"app123","password_confirmation":"app123"}}"

I我试过使用[]括号,我试过user = {data ..},没有什么似乎工作。任何想法?

I've tried every variation. I've tried using [] brackets, I've tried user={data..} and nothing seems to work. Any ideas?

推荐答案

首先,有一个无关的在你的命令结束。

First off, there is an extraneous " at the end of your command.

尝试此操作

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

这篇关于curl json post请求通过终端到rails应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆