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

  • 相关阅读:
    Python 5个极易混淆的核心概念
    【CCF CSP-20161203】权限查询
    修改this.$notify通知的样式
    【Java】volatile-内存可见性问题
    Spring Authorization Server 系列(二)获取授权码
    夜神模拟器+Burp抓包(简直是后端复现调试的福音)
    stream中map相关方法
    react中路由版本问题
    sql explain
    JS测试出最小支持字体,以及修复PDFJS的文本错误偏移
  • 原文地址:https://blog.csdn.net/sunnygirltest/article/details/140375182