from flask import Flask, request
import json
# 接收下发指令的http服务
app = Flask(__name__)
# POST请求
@app.route('/', methods=['POST'])
def http_server():
try:
# 获取POST请求的数据
data = json.loads(request.data.decode('utf-8'))
print(data)
# 响应数据
response_data = {
"code": 200,
"msg": "操作成功"
"data": {
}
}
# 返回响应
return json.dumps(response_data, ensure_ascii=False)
except Exception as e:
print(f"http_server Error: {e}")
# GET请求
@app.route("/mgcloud/mes_gis_gas_wifi/mesGisGasWifi/getairdata", methods=["GET"])
def get_data():
try:
# 响应数据
response_data = {
"code": 200,
"msg": "操作成功"
"data": {
}
}
# 返回响应
response = json.dumps(response_data, ensure_ascii=False)
return response
except Exception as e:
print(f"http_server Error: {e}")
if __name__ == '__main__':
# 设置服务的ip和端口
app.run(host="192.168.55.50", port=30001)
python使用flask实现http服务
最新推荐文章于 2024-07-25 13:14:25 发布