Reputation: 1519
I have a Rails application that my mobile app is trying to call. I tried testing the API through curl with the following command and it works.
curl -d "user[name]=bob&user[email][email protected]&user[password]=password&user[company_name]=hydra" linktomyapi
Now, I tried running the following command because when I send parameters through mobile app, I send them as a JSON format since I use AFNetworking for all my Networking calls, see below and this doesn't work.
curl -v -d '{"user[name]": "bob","user[email]": "[email protected]","user[password]": "password","user[company_name]": "rs"}' linktoMyApi
I am quite confused as to why this difference is? Could anyone suggest any ideas?
Upvotes: 2
Views: 558
Reputation: 20868
You have to pass an application/json Content-Type so rails can understand you are speaking json.
Add to your curl options : -H 'Content-Type:application/json'
Additionnaly, if you want to access your params with params[:user]
, you have to use a json object "user" to hold all the values :
{"user" : {"name": "bob", "email": "[email protected]", "password": "password", "company_name": "rs"}}
Upvotes: 3