在不知道其名称的情况下打印所有POST请求参数 [英] Print all POST request parameters without knowing their names

查看:303
本文介绍了在不知道其名称的情况下打印所有POST请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何打印使用Python和flask在POST请求中传递的所有参数?

我知道如何通过名称询问参数

I know how to ask for a parameter by name

from flask import  request
key = request.args.get('key')

但是我不确定为什么这对我不起作用:

But i'm not sure why this did not work for me:

for a in request.args:
        print "argument: " + a

推荐答案

request.args返回MultiDict.每个键可以有多个值.为了打印所有参数,您可以尝试:

request.args returns a MultiDict. It can have multiple values for each key. In order to print all parameters, you can try:

下面的代码适用于添加了参数的URL,例如:

The code below works for URLs with parameters added,like:

 http://www.webservice.my/rest?extraKey=extraValue
    multi_dict = request.args
    for key in multi_dict:
        print multi_dict.get(key)
        print multi_dict.getlist(key)

对于以表格形式嵌入在POST请求中的参数:

For parameters embedded within the POST request as a form:

dict = request.form
for key in dict:
    print 'form key '+dict[key]

请参见示例此处,您将会有个好主意

See the example here and you will have a good idea.

这篇关于在不知道其名称的情况下打印所有POST请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆