web.py:如何获取POST参数和GET参数? [英] web.py: how to get POST parameter and GET parameter?
问题描述
我是 web.py
的新手.我用了很多 PHP.PHP中POST参数和GET参数存放在不同的全局变量中
I'm new to web.py
. I used PHP alot. In PHP, POST parameter and GET parameter is stored in different global variables
例如:
curl http://127.0.0.1/test?get_param1=1 -d 'post_param1=2'
在 PHP 中,您可以得到 $_GET['get_param1']
为 1,$_POST['post_param1']
为 2.
In PHP you can get $_GET['get_param1']
is 1 and $_POST['post_param1']
is 2.
但是在 web.py
中区分 GET/POST 参数似乎是不可能的?
But it seems impossible to distinct GET/POST parameters in web.py
?
我只能使用 web.input()
在类似 dict 的对象中获取 GET/POST 参数,但我无法分辨哪些来自查询字符串,哪些来自 POST 数据
I can only use web.input()
to get GET/POST parameters in a dict-like object, but I cannot tell which of them is from the query string and which is from POST data
推荐答案
实际上有一个(未记录的?)_method
参数可以是 get
, post
或 both
(默认)从不同的来源返回变量.查看 web.input() 的源代码. 所以例如:
There's actually an (undocumented?) _method
parameter that can be get
, post
or both
(the default) to return variables from the different sources. See the source for web.input(). So for example:
get_input = web.input(_method='get')
post_input = web.input(_method='post')
然而,我经常使用 web.py,从来不需要这个.为什么需要区分查询字符串中的输入参数和数据?
However, I've used web.py a lot, and never needed this. Why do you need to distinguish between input parameters in the query string and the data?
这篇关于web.py:如何获取POST参数和GET参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!