使用cURL的嵌套参数? [英] Nested params with cURL?
问题描述
我有一个iPhone应用程序请求一个API,它使用嵌套的param结构传递用户名和密码登录。
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.
在我的Rails控制器,我正常使用以下方式成功检索此信息:
In my Rails controller, I'm successfully retrieving this information normally using:
username = param[:session][:username]
我想使用cURL从shell测试我的API。但我不知道如何提供嵌套参数?下面的代码不工作...我已经尝试了多个变体。
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
任何帮助,非常感谢!
推荐答案
不同的框架可能会解释http查询参数不同,可以使用以下命令:
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
这篇关于使用cURL的嵌套参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!