Simulate form message with arrays of nested resources using curl

How to use curl to make an http message in a form with nested attributes using application / x-www-form-urlencoded instead of application / xml?

It works fine with XML:

curl -i -X 'POST' -H 'Content-Type: application/xml' http://localhost:3000 -d '<user><name>John Doe</name><emails><email><address> jdoe@gmail.com </address></email><email><address> jdoe@yahoo.com </address></email></emails></user>' 

And the result:

 Parameters: {"action"=>"profile", "controller"=>"users", "user"=>{"name"=>"John Doe", "emails"=>{"email"=>[{"address"=>" jdoe@gmail.com "}, {"address"=>" jdoe@yahoo.com "}]}}} 

But I am trying to execute the same result without xml.

I tried like this:

 curl -i -X POST -d 'user[name]=John Doe&user[emails][email][address] =jdoe@gmail.com &user[emails][email][address] =jdoe@yahoo.com ' http://localhost:3000/ 

But this did not work:

 Parameters: {"user"=>{"name"=>"John Doe", "emails"=>{"email"=>{"address"=>" jdoe@yahoo.com "}}}} 
+4
source share
1 answer

You would try the following:

 curl -i -X POST -d 'user[name]=John Doe&user[emails][][email][address] =jdoe@gmail.com &user[emails][][email][address] =jdoe@yahoo.com ' http://localhost:3000/ 

Pay attention to [] for [emails]

+9
source

Source: https://habr.com/ru/post/1339717/


All Articles