1. 程式人生 > >python接口自動化測試九:重定向相關

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

head cts headers resp ons pri ima pytho response

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接口自動化測試九:重定向相關