日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python獲取http請求響應頭headers中的數據的示例_python

作者:woft王 ? 更新時間: 2022-04-19 編程語言

例如我要測試一個創建網絡的接口,需要先拿token值,而獲取token的接口請求成功后,將token存在了響應頭headers,postman調接口如下,現在想要通過python獲取下圖中

X-Subject-Token的值,供后續接口使用

方法:僅需要python的requests庫就可以實現

示例:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : 1.py
# @Author: ttwang
# @Date  : 2022/2/14
# @Desc  :python獲取http請求響應頭headers中的數據

import requests
import json
base_url = "http://xxxxxxxxx"
param = {
        xxxxxxxx
}
headers = {
    "Content-Type": "application/json",
res = requests.post(base_url + "/v3/auth/tokens",headers=headers,json=param,verify=False)
Token = res.headers.get("X-Subject-Token")

ps:同理,如果想獲取Date和Content_Type ,則:

Date = res.headers.get("Date")
Content_Type = res.headers.get("Content-Type")

原文鏈接:https://www.cnblogs.com/wwwwtt/p/15892233.html

欄目分類
最近更新