JMeter
使用Parameters时,Content-Type不传,或者直接传application/x-www-from-urlencoded,若传application/json出错。
使用Body Data时,Content-Type可传application/x-www-from-urlencoded或application/json,两者的区别是数据格式不同。
- json格式
content-type:application/json
![907a185153f935bd9b98ba7a51baf075.png](https://img-blog.csdnimg.cn/img_convert/907a185153f935bd9b98ba7a51baf075.png)
1.header-manager (信息头管理器)修改content-type值。
如果不修改该值, 则默认会是urlencode的数据格式(例如a=5&b=6)。
修改为json后,会告诉服务器,发送的数据为application/json格式数据。防止服务器对数据类型做强制校验。
![c366899423b47727c045ef69e09b0601.png](https://img-blog.csdnimg.cn/img_convert/c366899423b47727c045ef69e09b0601.png)
2. 添加一个http request 请求sample(取样器), 这样根据图示例进行配置,便可以轻松的实现发送json格式的数据。
其实还是用的post 方式发送参数, 只是参数的名称为空, value值是你要post的json字符串。
![92afc8fabd24982690774f3735fcb34a.png](https://img-blog.csdnimg.cn/img_convert/92afc8fabd24982690774f3735fcb34a.png)
![0977792dfd3d87d9cb998b9a3a6b12f2.png](https://img-blog.csdnimg.cn/img_convert/0977792dfd3d87d9cb998b9a3a6b12f2.png)
ps: 较新版本中的jmeter的http sampler(http请求采样器)已经有一个post body的标签, 可以直接填写post body值即可. 例如张图. 其实他和第二步中的设置内容是一致的.
![e6cf0fb57c38728092e12d713eff670f.png](https://img-blog.csdnimg.cn/img_convert/e6cf0fb57c38728092e12d713eff670f.png)
参考:巧妙的使用jmeter来发送json格式数据
- x-www-form-urlencoded格式:默认的。如果不指定content-type,默认使用此格式。
参数格式:key1=value1&key2=value2
content-type:application/x-www-form-urlencoded
![3116035455aee4b34f2177e696bce4e4.png](https://img-blog.csdnimg.cn/img_convert/3116035455aee4b34f2177e696bce4e4.png)
参数可以在Parameters(适用于get请求) 或 Body Data(适用于post请求)里输入,格式不同,如下图所示。
这两个参数输入的tab页只能使用一个,某一个有数据后不能切换到另一个。
Parameters:
![a5d7d93a487d2ead95d33bcf7c4d090a.png](https://img-blog.csdnimg.cn/img_convert/a5d7d93a487d2ead95d33bcf7c4d090a.png)
Body Data:
![cdb3ed0e832a8d87d8bcb1827bfa6e38.png](https://img-blog.csdnimg.cn/img_convert/cdb3ed0e832a8d87d8bcb1827bfa6e38.png)
参数格式:key1=value1&key2=value2 User=dinghanhua&Userphone=1312777772&
- content-type:multipart/form-data
上传文件用这种格式,抓包发送的请求示例:
传参格式:name="XXXX";value="XXXX"; 比如name="files";filename="2record.wav"
![54c337ce9ef723830c28af01b873f1c7.png](https://img-blog.csdnimg.cn/img_convert/54c337ce9ef723830c28af01b873f1c7.png)
这种头部信息类型在jmeter如何输入参数?
在http请求编辑页面,选中Use multipart/form-data for POST
比如上传pan卡接口:除了2个参数以外+文件
Parameters中输入除了上传的文件以外的参数:参数名和参数值
Files Upload中上传文件,文件名(文件放置位置),参数名:files和MIME类型
![8873b5ab65e89eda595253bd97147b7d.png](https://img-blog.csdnimg.cn/img_convert/8873b5ab65e89eda595253bd97147b7d.png)
![07696b36292fcbc557333efd9a3b9b55.png](https://img-blog.csdnimg.cn/img_convert/07696b36292fcbc557333efd9a3b9b55.png)
参考:jmeter(2)-几种不同的content-type方式 - 鱼小虾 - 博客园