以下代码可以作为测试接收请求的程序直接复制使用:
from flask import Flask, request
app = Flask(__name__)
@app.route('/service', methods=['POST'])
def post_route():
if request.method == 'POST':
headers = request.headers
data = request.get_json()
print'headers:',headers
print('Data Received: "{data}"'.format(data=data))
return "Request Processed.\n"
app.run()
请求命令如下
curl -H "Content-Type:application/json" -H "Data_Type:msg" -X POST --data '{"dmac": "00:0C:29:EA:39:70", "alert_type": "alarm", "risk": 2, "trojan_name": "Trojan.qq3344", "smac": "00:0C:29:EA:39:66", "sub_alert_type": "trojan", "sport": 11, "id": "153189767146", "desc": "NoSecure 1.2 \u6728\u9a6c\u53d8\u79cd4\u8fde\u63a5\u64cd\u4f5c", "sip": "62.4.07.18", "dip": "139.82.31.91", "rule_id": 123451, "trojan_type": 4, "time": "2018-07-18 15:07:51", "dport": 61621, "detector_id": "170301020011", "os": "Windows", "trojan_id": 50030}' http://127.0.0.1:5000/service