python接口自動化測試九:重定向相關


python接口自動化測試九:重定向相關

 

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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM