python获取http请求响应头headers中的数据的示例
作者:woft王
这篇文章主要介绍了python获取http请求响应头headers中的数据,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
例如我要测试一个创建网络的接口,需要先拿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")到此这篇关于python获取http请求响应头headers中的数据的文章就介绍到这了,更多相关python http响应头内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
