一培他、服務(wù)端
from flask import Flask,request
app = Flask(__name__)
#設(shè)置請求cookies
@app.route("/")
def set_cookies():
resp = make_response("成功")
resp.set_cookies("amumu","amm")
return resp
#創(chuàng)建一個GET接口
@app.route("/GetTime",methods=["GET"])
def GetTime():
now_time = time.strftime('%Y-%m-%d', time.localtime())
return {"Msg":"成功","NowTime":now_time}
#創(chuàng)建一個POST接口
@app.route("/Login",methods=["POST"])
def Login():
#接收客戶端發(fā)送的參數(shù)
acount = request.values.get("acount")
pwd = request.values.get("pwd")
#對客戶端參數(shù)進(jìn)行驗證并返回結(jié)果
if acount == "amumu" and str(pwd) == "123456":
rename = {"Msg":"成功","Name":"哈哈","Age":18,"Features":"英俊瀟灑"}
else:
rename = {"Msg": "您的用戶名或者密碼錯誤拗馒!"}
return rename
if __name__ == '__main__':
#設(shè)置接口返回JSON格式中文字符
app.json.ensure_ascii = False
#啟動接口并指定默認(rèn)端口
app.run(debug=True,port=80)
二华嘹、客戶端
客戶端POST請求
客戶端Get請求
客戶端POST請求返回信息
客戶端GET請求返回信息