Skip to content

Commit 16fa445

Browse files
committed
add flask 27
1 parent 10f32df commit 16fa445

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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())

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@
2525
23. [简单异步任务](https://xugaoxiang.com/2020/11/16/flask-23-threadpoolexecutor/)
2626
24. [http请求转发](https://xugaoxiang.com/2020/11/24/flask-24-http-proxy/)
2727
25. [接收多文件](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/)

0 commit comments

Comments
 (0)