简体   繁体   English

测试rails葡萄API与curl,params数组

[英]testing rails grape API with curl, params array

I am manually testing my rails application grape API using curl. 我使用curl手动测试我的rails应用程序葡萄API。 I would like to send a [1,2,3] array as a request query parameter for to to be accesible like: 我想发送一个[1,2,3]数组作为请求查询参数,以便可访问,如:

p params[:tickets_ids]
=> [1,2,3]

I only found clues how to send something what is interpreted as hash . 我只发现了如何发送被解释为哈希的东西的线索。

I will be grateful for a clue how to post an array using curl. 我将非常感谢如何使用curl发布数组。

Thank you for the clue. 谢谢你的线索。 The answer is to encode query like this: 答案是对这样的查询进行编码:

?&tickets_ids[]=1&tickets_ids[]=2&tickets_ids[]=3

Results in: 结果是:

p params[:tickets_ids]
=> ["1", "2", "3"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM