学无先后,达者为师

网站首页 编程语言 正文

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

栏目分类
最近更新