The following code can be copied directly as a program to test receiving requests:

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()
Copy the code

The request command is as follows:

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 ", "U53D8 ": "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
Copy the code

Note that:

1, --data (-d) The specified parameter must be in JSON format2, -h must be used individually to specify headers. That is, one -h specifies a header field, as shown in the CRUL example.Copy the code