Python接口自动化(六) session关联接口
session保持存会话
help(session())
通过help方法查看帮助文档。
使用session登录开源的OPMS系统,搭建OPMS系统,参考:https://www.cnblogs.com/canglongdao/p/12562972.html
#coding:utf-8 import requests url="http://47.98.16.11:8088/login" data={"username":"libai","password":"123456"} headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"} s=requests.Session() rs=s.post(url,data=data,headers=headers) print(rs.text) print(rs.json())
登录OPMS,新增项目,使用fiddler抓包;
python代码,参考fiddler抓包内容,填写;
#coding:utf-8 import requests url="http://47.98.106.11:8088/login" data={"username":"libai","password":"123456"} headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"} s=requests.Session() rs=s.post(url,data=data,headers=headers) print(rs.text) #新增项目 d={"name":"蛋糕1", "aliasname":"cake", "started":"2020-07-26", "ended":"2020-07-27", "desc":"good", "id":"0"} rs2=s.post("http://47.98.106.11:8088/project/add",data=d,headers=headers) print(rs2.json())
运行后,查看运行结果:
查看OPMS项目中多了一条“蛋糕1”的项目;
如上,session关联接口就是这么简单!!!
相关推荐
houmenghu 2020-11-17
我心似明月 2020-11-09
oraclemch 2020-11-06
ltd00 2020-09-12
康慧欣 2020-09-10
waveclouds 2020-09-04
蓝色深海 2020-09-15
jincheng 2020-09-01
思君夜未眠 2020-08-25
取个好名字真难 2020-08-06
歆萌 2020-08-03
阳光之吻 2020-08-03
婷婷小屋 2020-07-28
solarspot 2020-07-28
MLXY 2020-07-26
songbinxu 2020-07-19
83520298 2020-07-06
happinessaflower 2020-07-04