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,还可以用session
s=requests.session()
login_res=s.get(login_url,params=login_data)
recharge_res=s.post(recharge_url,recharge_data)
print("充值的结果是: ",recharge_res.json())