python+requests传两种参数体

在JMeter请求参数中,我们了解到,在做接口测试时,发送请求的参数有两种格式,一种是Parameters,一种是JSON。怎么区分请看 https://www.cnblogs.com/testlearn/p/10959217.html

那在python中,怎么使用requests传这两种格式的参数呢?

import requests

# Parameters参数体
data = {
    "mobile": "12345678901",
    "password": "123456"}
rs = requests.request("post", URL, data=data)    # 发送请求时,使用data传Parameters参数体
print(f"rs:{rs}")

# JSON参数体
token = rs.json()["data"]["ticketString"]
headers = {
    "token": token,
    "Content-Type": "application/json"
}
data = {
    "page": 1,
    "pageSize": 15}
rs1 = requests.request("post", URL, headers=headers, json=data)      # 发送请求时,使用json传Parameters参数体,使用headers传请求头
print(f"rs1:{rs1}")

原文地址:https://www.cnblogs.com/testlearn/p/11077831.html