File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1+ from flask import Flask , jsonify , request
2+
3+ app = Flask (__name__ )
4+
5+ @app .route ('/' , methods = ['POST' ])
6+ def post ():
7+
8+ # 获取请求的json数据
9+ req_json = request .get_json ()
10+ print (req_json )
11+
12+ # 对接收到的数据进行简单处理
13+ if req_json ["operatorID" ] != "0001" :
14+ return jsonify ({"error" : "error." })
15+
16+ dict_ret = {}
17+ dict_ret ["responseType" ] = 2
18+ dict_ret ["status" ] = 1000
19+ dict_ret ["num" ] = 1
20+ dict_ret ["MD5" ] = "4F3D2A1E"
21+
22+ return jsonify (dict_ret )
23+
24+
25+ if __name__ == '__main__' :
26+
27+ # 启动服务
28+ app .run (host = '0.0.0.0' , port = 80 , debug = True )
Original file line number Diff line number Diff line change 1+ import requests
2+
3+ r_json = {
4+ "name" : "xgx" ,
5+ "operatorID" :"0001" ,
6+ "requestType" :1 ,
7+ "num" :1
8+ }
9+
10+ r_headers = {"Content-type" : "application/json" }
11+
12+ r = requests .post ('http://127.0.0.1' , json = r_json , headers = r_headers )
13+ print (r .status_code )
14+ print (r .json ())
Original file line number Diff line number Diff line change 252523 . [ 简单异步任务] ( https://xugaoxiang.com/2020/11/16/flask-23-threadpoolexecutor/ )
262624 . [ http请求转发] ( https://xugaoxiang.com/2020/11/24/flask-24-http-proxy/ )
272725 . [ 接收多文件] ( https://xugaoxiang.com/2021/05/20/flask-25-receive-multiple-files/ )
28- 26 . [ flask-executor] ( https://xugaoxiang.com/2021/12/27/flask-26-flask-executor/ )
28+ 26 . [ flask-executor] ( https://xugaoxiang.com/2021/12/27/flask-26-flask-executor/ )
29+ 27 . [ 接收和发送json] ( https://xugaoxiang.com/2022/12/05/flask-27-json/ )
You can’t perform that action at this time.
0 commit comments