curl命令行POST

Kur*_*urt 15 curl ruby-on-rails

我正在尝试模拟我的简单Rails脚手架Web服务的POST.脚手架创建的文件尚未更改.当我从网站表单发布数据时,会正确创建记录.

当我尝试使用curl进行POST时,会在数据库中创建一条记录,但它在字段中具有NULL值,但"updated_at"和"created_at"除外.我是命令行卷曲的新手,所以我可能没有正确地做到这一点.

curl -d "name=Gazoo&friend=Rubble" localhost:3000/flintstones
Run Code Online (Sandbox Code Playgroud)

我从WEBrick那里得到了这个:

开始POST"/ flintstones"for 127.0.0.1 at Thu Apr 28 18:04:47 -0600 2011 Processing by FlintstonesController #create as Parameters:{"name"=>"Gazoo","friend"=>"Rubble"} AREL (0.3ms)INSERT INTO"flintstones"("name","friend","created_at","updated_at")VALUES(NULL,NULL,'2011-04-29 00:04:47.779902','2011-04- 29 00:04:47.779902')重定向到http:// localhost:3000/flintstones/4

在为Json获得GET之后

curl localhost:3000/flintstones.json

我收到:

[{ "打火石:{" 名称 ":NULL," created_at ":" 2011-04-29T00:09:58Z", "的updated_at": "2011-04-29T00:09:58Z", "ID":4, "朋友":空}}]

为什么我的字段中出现空值?

提前致谢.

Jef*_*sen 23

我用google搜索了一下,每个使用curl和rails web服务的例子都显示了格式中传递的参数

object[paramName]=paramValue

以及-d每个参数的一个集合,这将使您的CURL语句看起来像

curl -d "flintstone[name]=Gazoo" -d "flintstone[friend]=Rubble" localhost:3000/flintstones

以下是我引用的来源: