Ruby on Rails 3:如何分别检索POST和GET参数? [英] Ruby on Rails 3: How to retrieve POST and GET params separately?
问题描述
我知道您可以使用 params 获取参数,但事实是,无论它们是通过GET
还是POST
发送的,它都会合并所有参数:
I know you can get parameters using params, but the thing is that it merges all parameters whether they were sent via GET
or POST
:
如果您通过GET
发送请求,没问题,则只能在URL中压缩参数.
If you send a request via GET
, no problem, the parameters can only be squeezed in the URL.
但是,如果您发送的POST
请求具有类似/blabla?foo=bar&foo2=bar2
的URL,是否可以区分通过URL发送的变量和通过实际的POST
方法发送的变量之间的区别?>
But if you send a POST
request that has a URL like /blabla?foo=bar&foo2=bar2
, is there a way to tell the difference between the variables sent via the URL and the variables sent through the actual POST
method?
推荐答案
是的,在您的控制器中,您可以使用request.GET获取GET参数,并使用request.POST获取POST参数
Yes, in your controller you can get the GET parameters using request.GET and the POST parameters with request.POST
这篇关于Ruby on Rails 3:如何分别检索POST和GET参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!