获取所有post或者get请求参数

转自: https://blog.csdn.net/u013055678/article/details/70214756


目录结构:

app

|----static(空)

|----templates(空)

|----flaskapp.py


flaskapp.py:

[python] view plain copy
  1. # -*- coding: utf-8 -*-    
  2. #__author__="ZJL"    
  3.     
  4. from flask import Flask    
  5. from flask import request    
  6. from flask import make_response,Response    
  7.     
  8. import json    
  9.     
  10. app = Flask(__name__)    
  11.    
  12.    
  13. @app.route('/')    
  14. def hello_world():    
  15.     return 'hello world'    
  16.     
  17. def Response_headers(content):    
  18.     resp = Response(content)    
  19.     resp.headers['Access-Control-Allow-Origin'] = '*'    
  20.     return resp    
  21.    
  22. @app.route('/test', methods=['POST'])    
  23. def test():    
  24.     if request.method == 'POST' and request.form.get('aaa'):    
  25.         # POST:  
  26.         # request.form获得所有post参数放在一个类似dict类中,to_dict()是字典化  
  27.         # 单个参数可以通过request.form.to_dict().get("xxx","")获得  
  28.         # ----------------------------------------------------  
  29.         # GET:  
  30.         # request.args获得所有get参数放在一个类似dict类中,to_dict()是字典化  
  31.         # 单个参数可以通过request.args.to_dict().get('xxx',"")获得  
  32.         datax = request.form.to_dict()  
  33.         content = str(datax)    
  34.         resp = Response_headers(content)    
  35.         return resp    
  36.     else:    
  37.         content = json.dumps({"error_code":"1001"})    
  38.         resp = Response_headers(content)    
  39.         return resp    
  40.    
  41.    
  42. @app.errorhandler(403)    
  43. def page_not_found(error):    
  44.     content = json.dumps({"error_code""403"})    
  45.     resp = Response_headers(content)    
  46.     return resp    
  47.    
  48. @app.errorhandler(404)    
  49. def page_not_found(error):    
  50.     content = json.dumps({"error_code""404"})    
  51.     resp = Response_headers(content)    
  52.     return resp    
  53.    
  54. @app.errorhandler(400)    
  55. def page_not_found(error):    
  56.     content = json.dumps({"error_code""400"})    
  57.     # resp = Response(content)    
  58.     # resp.headers['Access-Control-Allow-Origin'] = '*'    
  59.     resp = Response_headers(content)    
  60.     return resp    
  61.     # return "error_code:400"    
  62.    
  63. @app.errorhandler(410)    
  64. def page_not_found(error):    
  65.     content = json.dumps({"error_code""410"})    
  66.     resp = Response_headers(content)    
  67.     return resp    
  68.    
  69. @app.errorhandler(500)    
  70. def page_not_found(error):    
  71.     content = json.dumps({"error_code""500"})    
  72.     resp = Response_headers(content)    
  73.     return resp    
  74.     
  75. if __name__ == '__main__':    
  76.     app.run(debug=True,threaded=True)   
  77.     

用request.form接收所有post参数



主要一次前端发请求过来的post参数个数不固定,如果用request.form['formname']这种形式会因为接收不到参数报500的错误



来源:网络


智能推荐

axios post请求后台获取不到参数

使用vue开发项目,ajax打算使用axios(听说很牛逼,就想试试)。结果发现post请求后台获取不到参数。 代码如下: axios.post('/v1/card/info', {                   ...

fiddler抓包-查看get与post请求参数

Fiddler抓包3-查看get与post请求 前言 前面两篇关于Fiddler抓包的一些基本配置,配置完之后就可以抓到我们想要的数据了,接下来就是如何去分析这些数据。 本篇以博客园的请求为例,简单分析get与post数据有何不一样,以后也能分辨出哪些是get,哪些是post了。   一、get请求 1.打开fiddler工具,然后浏览器输入博客首页地址:http://www.cnblo...

loadrunner get/post请求格式带json参数

本篇文章主要针对POST请求的三种数据请求格式,组织不同的脚本,较为基础,入手教简单 (1)、application/x-www-form-urlencoded 键值对 (2)、multipart/form-data 表单 (3)、application/json Json串 注意:loadrunner参数中的引号,需要自己加"\"。 1. application/x...

Jmeter接口测试——get与post请求参数传递方法

1. get请求的入参是json格式的 摘要: 利用httpClient调用接口,成功返回信息 接口地址: (RESTFUL方式) http://192.168.100.87:10051/ngcctcontrol/ws/interfaces/userSatisfy 请求方式: GET 步骤: 1、利用httpClient模拟接口调用正常情况。 输入报文: {    &...

springboot对Post,Get请求参数的接收

文章目录 1 接收Post请求 2 接收Get请求 1 接收Post请求 post Content-Type:application/json 使用@RequestBody post Content-Type: multipart/form-data post Content-Type: application/x-www-form-urlencoded 这两种都可以使用@ModelAttribu...

猜你喜欢

POST获取参数。【POST】

请求后台controller的时候经常需要传递参数过来。当请求方式为GET 的时候就可以很容易的获取到参数,通过request对象即可 当使用 GET 传输的时候就可以采用上述的方式获取,但是GET传输是将参数直接拼接在URL后面,通过地址栏传输,一些敏感的参数会直接暴漏同时GET传输对于参数的长度也有所限制,所以很多时候需要我们通过POST传输,而当利用上面的方法获取POST传输的参数就会发现我...

Android POST GET请求

          Android应用经常会和服务器端交互,这就需要手机客户端发送网络请求,下面介绍常用的两种网络请求方式POST,GET。首先要区别POST和GET请求 1. GET是从服务器上获取数据,POST是向服务器传送数据。 2. GET是把参数数据队列加到提交表单的ACTION属性所指的URL中,...

GET,POST请求区别

1. 一般来说GET是获取数据,POST是提交数据的。但是因为GET和POST都是HTTP的方法,HTTP又是是基于TCP/IP的关于数据在万维网中 如何让通讯的协议。所以本质上来说GET和POST请求是没有区别 的,都是TCP链接。他们能做的事情是一样的。 HTTP协议既然有了这两个方法,就是为了在特定的情况下区分应用。就有了我们所说的GET是获取数据,POST是提交数据的。 2. GET传输数...

flex布局居中无效果注意是否设置了宽度

View 是flex布局;JDTouchable是flex:1;设置居中,  里面的两个View必须提供宽度,才能居中!...

mysql查询语句6:子查询

说明:当一个查询语句中又嵌套了另一个完整的select语句,则被嵌套的select语句称为子查询或内查询。外面的select语句称为主查询或外查询。 注:子查询不一定必须出现在select语句内部,只是出现在select语句内部的情况较多。 分类: 按子查询出现的位置进行分类: 1、select后面 要求:子查询的结果为单行单列(标量子查询) 2、from后面 要求:子查询的结果可以为多行多列 3...

问答精选

How can I use SET in MYSQL to combine 2 values?

I wanted to SET a value into a VARCHAR but I don't understand how to combine it. Somehow I am losing the textpart "This is a test". Is this normal behaviour for MySQL, am I doing something w...

How to find the center in unity 2d?

I want to create 2d game. The game is similar to the Scale Puzzle. I've already created nearly all the functionality. Only the last remains. . This is example. And that's how I draw shapes. . I click ...

PHP question on how to display data?

How can I accomplish the following. For example lets say I already have a template that checks to see if the user has entered a link if not it will not display the link template if so display the link...

Allow match - special characters should only appear once in a row

I have a regex that cleans string of all unwanted characters. Allowed characters (matches) are A-Z a-z 0-9 - and / What i have so far works like it should: The only thing i cannot achieve is that - sh...

How to delete sheet from an existing excel file using JExel

I am trying to delete sheet from an existing excel file. can any one suggest how to do that. It depends what you're trying to achieve. Brute force method: the never Excel file format (*.XLSX) is just ...

相关问题

相关文章

热门文章

推荐文章

相关标签

推荐问答