requests接口自动化4-登录后才能访问的get请求,需共享cookie

登录后才能访问的get请求,需共享cookie

fiddler里请求响应结果:

requests接口自动化4-登录后才能访问的get请求,需共享cookie_第1张图片

 

 

代码:

import requests
import json
#form表单形式的post请求,用data传参,Content-Type: application/x-www-form-urlencoded
payload={"username":"admin","password":"admin","validateCode":"","rememberMe":"false"}
s=requests.session()
response3=s.post("http://www.luckyframe.cn/login",data=payload)
#登录后,s里继承了cookie信息,可以直接发送其他请求
response4=s.get('http://www.luckyframe.cn/testexecution/taskCaseExecute/getMainData.do?_=1592060167330')
#把响应内容转换为json对象
data1=response4.json()
#打印响应文本
print(response4.text)
print(data1)

 运行结果:

D:\Python37\python.exe E:/PycharmProjects/home_UI/apistudy/requestsstudy.py
{"caseadddata":["0","0"],"casedata":["0","0"],"taskdata":["0天0小时0分钟","0"],"logdata":["0","0"]}
{'caseadddata': ['0', '0'], 'casedata': ['0', '0'], 'taskdata': ['0天0小时0分钟', '0'], 'logdata': ['0', '0']}

  

你可能感兴趣的:(requests接口自动化4-登录后才能访问的get请求,需共享cookie)