網站首頁 編程語言 正文
例如我要測試一個創建網絡的接口,需要先拿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
相關推薦
- 2022-07-24 示例剖析golang中的CSP并發模型_Golang
- 2022-05-13 this.$route.params獲取不到
- 2022-02-02 ionic 禁止橫屏處理
- 2022-09-13 Python判斷和循環語句的分析與應用_python
- 2022-09-19 利用Python實現批量打包程序的工具_python
- 2022-05-26 C/C++調用Fortran的DLL的操作過程_C 語言
- 2023-03-01 GoLang?Time時間操作函數講解_Golang
- 2022-02-19 springboot log4j2-dev.xml打成war包部署到tomcat無效
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支