Python test interface - get the content of the response response

import json
from sign1 import parm
import requests
parmB = parm
URL = 'https://xxxxxxxxxx'
header = {
    
    'Accept': "application/json, text/plain, */*",
          'content-type': "application/x-www-form-urlencoded;charset=UTF-8"}
r = requests.post(url = URL, headers = header, data = parmB)

# 请求的URL
print('请求的URL:', r.url)

# 获取响应头数据
print('响应头信息:', r.headers)
print('响应头的Content-Type:', r.headers.get('Content-Type'))

# 获取响应状态码
print('响应状态码:', r.status_code)

# 以文本的形式显示响应
print('以文本的形式显示响应:', r.text)

# 获取响应字符串编码
print('响应字符串编码:', r.apparent_encoding)

# 获取字节形式的响应内容,会将汉字转换成二进制码(主要用来传递图片、视频、文件时候用到)
print('字节形式的响应内容:', r.content)

# 获取字节形式的相应内容并用utf-8格式来解码
print('解码之后的样式:', r.content.decode('utf-8'))

# 对响应对象进行.json()操作,.json操作返回的是一个字典类型
r_json = r.json()
a = r_json['resObj'][0]['activityId']  # 取list里第一个activityId
print('第一个activityId:', a)

Results of the:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43466526/article/details/125739168