码迷,mamicode.com
首页 > 编程语言 > 详细

python接口自动化测试九:重定向相关

时间:2018-08-29 14:01:25      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:返回   response   dir   head   blog   type   info   9.png   stat   

 

allow_redirects=False  不重定向

# 获取重定向后的地址
loc = r.headers

 技术分享图片

 

 

 

# 相对地址
host = ‘https://i.cnblogs.com/‘
url = host+‘EditPosts.aspx?opt=1‘

loc = r.headers[‘Location‘]
url1 = host+loc     # 拼接出重定向后的地址

 技术分享图片

 

 

 

 

# 追踪重定向过程
his = r.history
print(type(his))
print(his)
# 追踪第二个请求内容
r2 = his[1]
print(r2)

 技术分享图片

 

# 通过Response对象,来获取返回内容
print(r2.url)
print(r2.status_code)
print(r2.headers)
print(r2.test)

技术分享图片

python接口自动化测试九:重定向相关

标签:返回   response   dir   head   blog   type   info   9.png   stat   

原文地址:https://www.cnblogs.com/dwdw/p/9553079.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!