allow_redirects=False  不重定向

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

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

 

 

 

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

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

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

 

 

 

 

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

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

 

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

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

相关文章:

  • 2022-12-23
  • 2021-09-18
  • 2021-09-03
  • 2021-09-07
  • 2022-01-08
  • 2021-08-01
  • 2021-09-13
  • 2021-05-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-06-17
  • 2021-12-03
相关资源
相似解决方案