本代码是采用flask创建服务器,简单清晰可运行的代码,多余的import自行删除即可。
然后,当flask遇到不能处理的mimetype时,请求的数据就不能被其它方式正常解析,这些方式包括request.form、request.json和
request.files这几个常用的用来访问数据的属性。这时就把数据作为字符串存在request.data中。
这里注意一下request.json需要application/json的mimetype类型。
知道了这些处理数据的过程,那我们就可以对提交的数据进行扩展,定义一些自己专用的mimetype类型,并在Request类中定义处理专用mimetype数据的方法,从而让我们实现更个性、与众不同的功能需求。
from flask import Flask, request, Response
import json
from get_action import get_action
from card_get import get_card_valueapp = Flask(__name__)sendmesg = {"code": 0,"gameId":None,"userId": None,"action": [],"delay": 0,}#自定义url地址名字为scmjgamelogic,按自己需要更改,处理get请求将method改为get即可
@app.route('/scmjGameLogic', methods=['POST'])
def register():print("headers:",request.headers)data = request.jsonprint("data:",data)mesg = datacurPos = mesg["curPos"]history = mesg["history"]try:userid = mesg["userId"]sendmesg["userId"] = useridexcept:passgameid = mesg["gameId"]lastpos = history[-1][0]card_value = history[-1][2]card_value = get_card_value(card_value[0], card_value[1])sendmesg["gameId"] = gameidsendmesg["action"] = get_action(history,curPos,lastpos,card_value)return Response(json.dumps(sendmesg), mimetype='application/json')if __name__ == '__main__':app.run(host = "",port=6999, debug=True)
host地址采用本地IP地址,端口号需要检查开不开放










