curl命令行POST [英] curl command line POST
问题描述
我试图模拟一个POST到我简单的Rails scaffold web服务。由scaffold所创建的文件尚未更改。当我从网站表单POST数据,正确创建一个记录。
当我尝试使用curl POST时,在数据库中创建一个记录,但它有NULL字段中的值,updated_at和created_at除外。我是新的命令行curl,所以我可能不会正确做。
curl -dname = Gazoo& friend = Rubblelocalhost:3000 / flintstones
我从WEBrick回到这里:
2011年4月28日发布的POST/ flintstonesfor 127.0.0.1由FlintstonesController处理#create as parameters:{name =>Gazoo,friend=>Rubble} AREL(0.3ms)INSERT INTOflintstones(name,friend,created_at,updated_at)VALUES(NULL,NULL, -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
/ p>
[{flintstone:{name:null,created_at:2011-04-29T00:09:58Z,updated_at:2011-04 -29T00:09:58Z,id:4,friend:null}}]
为什么我的字段为空?
提前感谢。
我已经google了一下,使用curl和rails web服务显示以格式
传递的参数 object [paramName] = paramValue
p>
以及为每个参数设置一个 -d
,这将使您的CURL语句看起来像
curl -dflintstone [name] = Gazoo-dflintstone [friend] = Rubblelocalhost:3000 / flintstones
p>
这里是我引用的来源:
I'm trying to simulate a POST to my simple Rails scaffold web service. The files created by the scaffold have not been changed. When I POST data from the website form, a record is created correctly.
When I attempt to POST with curl, a record is created in the database, but it has NULL values in the fields, except for 'updated_at' and 'created_at'. I'm new to command line curl so I may not be doing it correctly.
curl -d "name=Gazoo&friend=Rubble" localhost:3000/flintstones
I get back this from WEBrick:
Started 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') Redirected to http://localhost:3000/flintstones/4
After a GET for the json
curl localhost:3000/flintstones.json
I receive:
[{"flintstone:{"name":null,"created_at":"2011-04-29T00:09:58Z","updated_at":"2011-04-29T00:09:58Z","id":4,"friend":null}}]
Why do I get null in my fields?
Thanks in advance.
I've googled a bit and every example of using curl with a rails web service shows the parameters passed in the format
object[paramName]=paramValue
as well as one -d
set for each parameter which would make your CURL statement look like
curl -d "flintstone[name]=Gazoo" -d "flintstone[friend]=Rubble" localhost:3000/flintstones
Here are the sources I'm referencing:
这篇关于curl命令行POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!