自学内容网 自学内容网

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);


原文地址:https://blog.csdn.net/sunnygirltest/article/details/140375182

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!