服务端:
# -*- coding:utf-8 -*-
"""
@author: Looking
@email: [email protected]
"""
from flask import Flask, request
app = Flask(__name__)
@app.route('/data', methods=['POST'])
def testpost():
if request.method == 'POST':
temp = request.json.get('data')
print(temp)
return "success"
if __name__ == '__main__':
app.run(host="0.0.0.0", port=9979, threaded=True)
客户端:
# -*- coding:utf-8 -*-
"""
@author: Looking
@email: [email protected]
"""
import requests
if __name__ == '__main__':
url = "http://服务端公网IP:9979/data"
data = {
"aaa": 1,
"bbb": 2,
}
r = requests.post(url, json={"data": data})
print(r.text)
服务端运行结果:
[root@zlsw looking]# python3 receive_data.py
* Serving Flask app "receive_data" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:9979/ (Press CTRL+C to quit)
{'aaa': 1, 'bbb': 2}
1.80.1.112 - - [26/Sep/2019 09:18:53] "POST /data HTTP/1.1" 200 -
客户端运行结果:
"D:\Program Files\Python36\python3.exe" D:/MyProject/Python/HeshunAudio/post_request.py
success
Process finished with exit code 0