Cookie简介
Cookie使用场景
在接口测试过程中, 很多情况下,需要发送的请求附带cookies,才能返回正常的结果。所以在使用python+requests进行接口自动化测试也是同理, 需要在构造接口测试用例时加入cookie。
传递Cookie的两种方式:
1. 请求头headers信息传递
import requests def test_demo(): url = "https://httpbin.testing-studio.com/cookies" header = {"Cookie":"name = xuefeifei"} r = requests.get(url =url,headers=header) print(r.request.headers)
2.通过请求的关键字参数cookies传递
import requests def test_demo(): url = "https://httpbin.testing-studio.com/cookies" cookie_data = {"name":"xuefeifei"} r = requests.get(url =url,cookies = cookie_data) print(r.request.headers)