Nested params with cURL?

怎甘沉沦 提交于 2019-12-18 11:47:18

问题


I've got an iPhone app requesting an API, and it uses a nested param structure to pass in a username and password to login.

In my Rails controller, I'm successfully retrieving this information normally using:

username = param[:session][:username]

I'd like to test my API from shell, using cURL. But I can't figure out how to provide nested params? The code below does NOT work... And I've tried multiple variations. But just can't seem to figure it out?

curl -d '{"session":{"username":"test","password":"password"}}' http://testurl/remote/v1/sessions

Any help, much appreciated!


回答1:


Different frameworks may interpret http query params differently, but for rails you should be able to get away with the following:

curl -d 'session[username]=name&session[password]=pwd' http://testurl/remote/v1/sessions



回答2:


I found this to work. Given a JSON blob like

{ "opts": {
    "finder": { 
      "cname":"superlatives"
    }
  }
}



curl -H "Content-Type: application/json" \
  -X POST \
  --data-binary '{"opts":{"finder":{"cname":"superlatives"}}}' \
  http://YOURSERVER.com/api/grams/one


来源:https://stackoverflow.com/questions/3860654/nested-params-with-curl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!