二、flask创建mock
1、导入模块 Flask
2、实现
import hashlib
from flask import Flask,request
#初始化实例
app = Flask(__name__)
#装饰器 绑定访问路径:访问绑定目录时调用函数
@app.route('/request',methods=['POST','GET'])
def requestsss():
return 'hello request'
#加密
def Md5(args):
return hashlib.md5(str(args).encode('utf-8')).hexdigest()
#模拟待参数请求--MD5加密接口
@app.route('/login',methods=['POST'])
def login():
#接收传参
username = request.values.get('username')
passwd = request.values.get('passwd')
print(username,passwd)
if username == Md5('admin') and passwd == Md5('123'):
return 'success'
else:
return 'error'
if __name__ == '__main__':
#调用run函数生成路径
app.run()
3、通过postman向生成的服务器地址发送请求