jmeter文件下载接口处理

jmeter下载文件是以流的形式进行的,所以经常会卡,需要处理下。使用BeanShell PostProcessor即可。其中file_name为下载文件存储路径。

byte[] result = prev.getResponseData();
String file_name ="/Users/apple/Desktop/tmp/${fileName}";
File file = new File(file_name);
FileOutputStream out = new FileOutputStream(file);
out.write(result);
out.close();

import java.nio.charset.StandardCharsets;
import org.json.JSONArray;
import org.json.JSONObject;
import org.apache.jmeter.functions.Encode;

String term_id = vars.get(“term_id”);
String term_name = vars.get(“sensitiveWordName”);

// 创建 JSON 对象
JSONObject jsonObject = new JSONObject();
jsonObject.put(“logic_opr”, “or”);

JSONArray conditionsArray = new JSONArray();
JSONObject conditionObject = new JSONObject();
conditionObject.put(“type”, 2);
conditionObject.put(“term_type”, 2);

JSONArray termsArray = new JSONArray();
JSONObject termObject = new JSONObject();
termObject.put(“term_id”, term_id);
termObject.put(“term_name”, term_name);
termObject.put(“match_number”, 1);
termsArray.put(termObject);

conditionObject.put(“terms”, termsArray);
conditionObject.put(“part_number”, 1);

conditionsArray.put(conditionObject);
jsonObject.put(“conditions”, conditionsArray);

// 将 JSON 对象转换为字符串
String jsonString = jsonObject.toString();

// 对JSON字符串进行Base64编码
String encodedString = Encode.encodeBase64(jsonString.getBytes(StandardCharsets.UTF_8));

// 将编码后的字符串设置为请求参数
vars.put(“encodedParam”, encodedString);

使用 Base64 编码字符串
//byte[] encodedBytes = Base64.encodeBase64(jsonString.getBytes());
//String encodedString = new String(encodedBytes);
//
//vars.put(“encodedString”, encodedString);

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值