jmeter BeanShell PostProcessor 获取http请求的入参,存入CSV

1、在http请求前新建一个jmeter BeanShell PostProcessor,其与http请求同在一个线程组内。

 

 

2、下载fastjson-2.0.14.jar包放在jmeter的lib目录下

 

下载路径为:https://mvnrepository.com/artifact/com.alibaba/fastjson/2.0.14

 3、测试计划加载fastjson-2.0.14.jar包

 

 4、BeanShell PostProcessor插件写如下代码,用于获取入参里的fund_account和ext_txn_reference,并存入CSV:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import org.json.*;
import com.alibaba.fastjson.*;
import java.io.*;
//获取接口中的请求参数
String request=ctx.getCurrentSampler().getArguments().getArgument(0).getValue();
log.info("request is:"+request);
//将请求参数转为JSON格式
JSONObject data_obj=JSON.parseObject(request);
//拿到指定入参
String data_1=data_obj.getString("fund_account");
log.info("fund_account is: "+data_1);
String data_2=data_obj.getString("ext_txn_reference");
log.info("ext_txn_reference is: "+data_2);
FileWriter file=new FileWriter("D:\\456.csv",true);
BufferedWriter out = new BufferedWriter(file);
out.write(data_1+','+data_2+"\n");
out.close();
file.close();

下图所示即为入参:

 

下图所示即为代码:

 

 下图所示即为存在CSV的数据:

 

posted @   小白成长记-yan  阅读(863)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示