Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate a form post with nested resources arrays using curl

How to use curl to make a http post on a form with nested attributes using application/x-www-form-urlencoded, instead of application/xml?

With XML it works just fine:

curl -i -X 'POST' -H 'Content-Type: application/xml' http://localhost:3000 -d '<user><name>John Doe</name><emails><email><address>[email protected]</address></email><email><address>[email protected]</address></email></emails></user>'

And the result:

Parameters: {"action"=>"profile", "controller"=>"users", "user"=>{"name"=>"John Doe", "emails"=>{"email"=>[{"address"=>"[email protected]"}, {"address"=>"[email protected]"}]}}}

But, I'm trying to accomplish the same result without xml.

I tried like this:

curl -i -X POST -d 'user[name]=John Doe&user[emails][email][address][email protected]&user[emails][email][address][email protected]' http://localhost:3000/

But it didn't worked:

Parameters: {"user"=>{"name"=>"John Doe", "emails"=>{"email"=>{"address"=>"[email protected]"}}}}
like image 378
Pablo B. Avatar asked Jan 21 '23 12:01

Pablo B.


1 Answers

would you please try the following:

curl -i -X POST -d 'user[name]=John Doe&user[emails][][email][address][email protected]&user[emails][][email][address][email protected]' http://localhost:3000/

Note the [] behind [emails]

like image 123
Michael Schäfermeyer Avatar answered Jan 23 '23 00:01

Michael Schäfermeyer