Request cookie设置

Request cookie设置,第1张

1.设置cookie

思路:设置cookie并获取

port requests

base_url='http://httpbin.org'

cookie={'user':'wx','password':'123'}

r=requests.get(base_url+'/cookies',cookies=cookie)

print(r.text)

2.获取cookie

用items()方法遍历cookie元祖列表内容并打印

import requests

r=requests.get('http://www.baidu.com')

print(type(r.cookies))

print(r.cookies)

for key,value in r.cookies.items():

    print(key+':'+value)

//设置cookie

response.addHeader("Set-Cookie", "uid=112Path=/HttpOnly")

//设置多个cookie

response.addHeader("Set-Cookie", "uid=112Path=/HttpOnly")

response.addHeader("Set-Cookie", "timeout=30Path=/testHttpOnly")

//设置https的cookie

response.addHeader("Set-Cookie", "uid=112Path=/SecureHttpOnly")


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11288036.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存