一、服务端
from flask import Flask,request
app = Flask(__name__)
#设置请求cookies
@app.route("/")
def set_cookies():
resp = make_response("成功")
resp.set_cookies("amumu","amm")
return resp
#创建一个GET接口
@app.route("/GetTime",methods=["GET"])
def GetTime():
now_time = time.strftime('%Y-%m-%d', time.localtime())
return {"Msg":"成功","NowTime":now_time}
#创建一个POST接口
@app.route("/Login",methods=["POST"])
def Login():
#接收客户端发送的参数
acount = request.values.get("acount")
pwd = request.values.get("pwd")
#对客户端参数进行验证并返回结果
if acount == "amumu" and str(pwd) == "123456":
rename = {"Msg":"成功","Name":"哈哈","Age":18,"Features":"英俊潇洒"}
else:
rename = {"Msg": "您的用户名或者密码错误!"}
return rename
if __name__ == '__main__':
#设置接口返回JSON格式中文字符
app.json.ensure_ascii = False
#启动接口并指定默认端口
app.run(debug=True,port=80)
二、客户端