request模块部分
import requests import json if __name__ == '__main__': url = 'http://127.0.0.1:5000' data = {"imageId": "xxxx", "base64Data": "xxxx", "format": "jpg", "url": "xxxxx"} data = json.dumps(data) r = requests.post(url, data=data) print(r.text)
flask服务端接收请求代码
from flask import Flask,request app = Flask(__name__) @app.route("/", methods=["POST"]) def view_func_2(): data = request.get_json() if data: pass else: data = request.get_data() data = json.loads(data) imageId = data["imageId"] base64Data = data["base64Data"] format = data["format"] url = data["url"] print(data) print(imageId) print(base64Data) print(format) print(url) return "OK" if __name__ == '__main__': app.run(host="0.0.0.0",port=5000)