Python接口自动化

1.项目流程:注册-》登录-》充值

登录会产生cookies,充值需要用到登录产生的cookies才可以充值成功

代码如下

import requests#注册# register_url=‘testlink/register‘# register_data={"mobilephone":"15950123333","pwd":"123456","regname":"Mar"}# res=requests.get(register_url,register_data)# print("text解析结果",res.text)# print("text解析结果",res.json())#登录login_url=‘testlink/login‘login_data={"mobilephone":"15950123333","pwd":"123456"}res_login=requests.get(login_url,login_data)print("text解析结果",res_login.text)print("text解析结果",res_login.json())#充值方法一recharge_url=‘testlink/recharge‘recharge_data={"mobilephone":"15950123333","amount":"12"}# res_recharge=requests.get(recharge_url,recharge_data,cookies=res_login.cookies)# print("text解析结果",res_recharge.text)# print("text解析结果",res_recharge.json())#充值方法二,不用cookies,还可以用sessions=requests.session()login_res=s.get(login_url,params=login_data)recharge_res=s.post(recharge_url,recharge_data)print("充值的结果是: ",recharge_res.json())

相关推荐