curl - 使用 cURL 嵌套参数?

标签 curl params

我有一个请求 API 的 iPhone 应用程序,它使用嵌套的参数结构来传递用户名和密码以进行登录。

在我的 Rails Controller 中,我通常使用以下方法成功检索此信息:

username = param[:session][:username]

我想使用 cURL 从 shell 测试我的 API。但我不知道如何提供嵌套参数?下面的代码不起作用......我尝试了多种变体。但似乎无法弄清楚?
curl -d '{"session":{"username":"test","password":"password"}}' http://testurl/remote/v1/sessions

任何帮助,非常感谢!

最佳答案

不同的框架可能会以不同的方式解释 http 查询参数,但对于 Rails,您应该能够摆脱以下情况:

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

关于curl - 使用 cURL 嵌套参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3860654/

相关文章:

php - 帮助我理解 CURLOPT_READFUNCTION

php - 为什么 php curl 不在我的 cookiefile 中保存 cookie?

ruby-on-rails - rails : Different Controller behaviour depending on route

docker - 在Dockerfile中应用CA根证书

php - cURL 返回二进制数据而不是 html

xslt - 如何在 xslt 中设置标志/变量以再次输入(与转换为 Junit 格式有关)

ruby-on-rails - RSpec请求测试合并了POST JSON参数中数组中的哈希

ruby-on-rails - 如何从 LinkedIn 解析 Mash 以创建 Ruby 对象

javascript - 使用 curl 打开 url,单击 ajax 按钮,等待并获取响应 html

ruby-on-rails - 嵌套属性错误 : no implicit conversion of String into Integer