当前位置:网站首页>技术分享 | 实战演练接口自动化如何处理 Form 请求?
技术分享 | 实战演练接口自动化如何处理 Form 请求?
2022-08-11 05:36:00 【叶赫那拉 赫敏】
在服务端自动化测试过程中,Form 请求代表请求过程中,请求体为表单类型。其特点为:数据量不大、数据层级不深的情况、使用键值对传递。Form 请求头中的content-type通常对应为application/x-www-form-urlencoded。碰到这种类型的接口,使用 Java 的 REST Assured 和 Python 的 Requests 均可解决。
实战练习
Python 版本
在 Python 版本中,可以使用 data 参数传输表单数据,data 参数以字典的形式,字典是以键值对的形式出现。
class TestFormData:
def test_data(self):
data = {
"school":"hogwarts"
}
r = requests.post("https://httpbin.ceshiren.com/post",
data=data)
print(r.json())
运行结果:
{
"args": {},
"data": "",
"files": {},
"form": {
"school": "hogwarts"
},
...省略...
"json": null,
"origin": "113.89.10.187",
"url": "https://httpbin.ceshiren.com/post"
}
Java 版本
import static io.restassured.RestAssured.*;
public class Requests {
public static void main(String[] args) {
given().formParams("school", "hogwarts").when().post("https://httpbin.ceshiren.com/post").
then().log().all();
}
}
使用抓包工具查看过程数据(参考代理配置章节),其中多了 Form 格式展示,以 name 和 value 的形式显示,具体结果如下图所示:

边栏推荐
- OA项目之项目简介&会议发布
- Daily sql-employee bonus filtering and answer rate ranking first
- Daily SQL - find each of the students school gpa minimum (window)
- Pinduoduo api interface application example
- 获取拼多多商品信息操作详情
- 抖音API接口大全
- sql--Users who have purchased more than 3 times (inclusive) within 7 days (including the current day), and the purchase amount in the past 7 days exceeds 1,000
- pytorch调整模型学习率
- Douyin API interface
- Implement general-purpose, high-performance sorting and quicksort optimizations
猜你喜欢
随机推荐
每日sql-员工奖金过滤和回答率排序第一
mmdetection的安装和训练、测试didi数据集的步骤(含结果)
Daily sql - judgment + aggregation
HCIP OSPF/MGRE综合实验
Redis + lua implements distributed interface current limiting implementation scheme
Eight-legged text jvm
radix-4 FFT principle and C language code implementation
HCIP-Spanning Tree (802.1D, Standard Spanning Tree/802.1W: RSTP Rapid Spanning Tree/802.1S: MST Multiple Spanning Tree)
MySQL 版本升级心得
Amazon Get AMAZON Product Details API Return Value Description
HCIA知识复习
OA项目之我的会议(会议排座&送审)
Daily sql-seek the sum of successful investments in 2016
亚马逊API接口大全
抖音分享口令url API工具
【深度学习】什么是互信息最大化?
八股文之mysql
iptables 使用脚本来管理规则
numpy和tensor增加或删除一个维度
HCIP MGRE\OSPF Comprehensive Experiment