cookie简介
-
cookie使用场景
- 在接口测试过程中,很多情况下需要发送附带cookie的请求,才会得到正常的响应
-
传递cookie的两种方式
- 通过请求头信息传递
- 通过请求关键字cookies传递
携带cookies示例
def test_with_cookie(self):
url = "https://httpbin.ceshiren.com/cookies"
cookie = "school=hogwarts"
header = {"Cookie": cookie}
res = requests.get(url, headers=header, proxies=self.proxies, verify=False)
print(res.request.headers)
cookie = dict(teacher="ad")
res = requests.get(url, cookies=cookie, proxies=self.proxies, verify=False)
print(res.request.headers)