简体   繁体   English

作用域为数组类型时,如何在url中正确写入参数?

[英]How to correctly write parameter in url when scope is array type?

I created a scope and pointed it to the array type. 我创建了一个作用域,并将其指向数组类型。

has_scope: by_industry,: type =>: array

And now I want to make this scope working. 现在,我想使此示波器起作用。

I tried to pass parameter in url like this: 我试图像这样在url中传递参数:

http://localhost:3000/v1/find_friends?by_industry=[1,2]

Does not work. 不起作用。

How to correctly write parameter in url when scope is array type? 作用域为数组类型时,如何在url中正确写入参数?

To pass arrays through query parameters you use the key + brackets syntax: 要通过查询参数传递数组,请使用key +方括号语法:

?foo[]=1&foo[]=2

It's klunky and its ugly but thats how its been done since the early days of the web and this old CGI convention is used by Rack. 它很笨拙而且很丑陋,但这就是Rack自网络初期和这种古老的CGI约定以来的工作方式。 The main advantage vs foo=[1,2] is that it is language agnostic and the params can be parsed out without interpreting the string (which is a security hazard). foo=[1,2]相比,主要优点是它与语言无关,并且可以在不解释字符串的情况下解析出参数(这是安全隐患)。

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

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