gpt4 book ai didi

web-services - 如何在 Jmeter 中对 Base64 的附件进行编码?

转载 作者:行者123 更新时间:2023-12-03 14:12:02 28 4
gpt4 key购买 nike

我正在尝试在 Jmeter 中将文件编码为 Base64 以使用以下脚本测试 Web 服务:

String file = FileUtils.readFileToString(new File("${filepath}"), "UTF-8");
vars.put("file", new String(Base64.encodeBase64(file.getBytes("UTF-8"))));

这适用于纯文本/文本文件,但不适用于其他文件类型。

我怎样才能使它适用于其他文件类型?

最佳答案

Jmeter 有很多方法可以将变量转换为“Base64”,下面是一些选项

  • bean shell 预处理器
  • BeanShell 后处理器
  • bean shell 采样器。

  • 下面是“bean shell”代码,它在“Bean shell pre processor”中用于将变量转换为Base64

    import org.apache.commons.codec.binary.Base64;

    String emailIs= vars.get("session");

    byte[] encryptedUid = Base64.encodeBase64(emailIs.getBytes());
    vars.put("genStringValue",new String(encryptedUid));

    例子 :

    Base64 之前:jdwqoeendwqqm12sdw

    Base64 后:amR3cW9lZW5kd3FxbTEyc2R3

    使用 Jmeter 转换:

    enter image description here

    enter image description here

    enter image description here
    使用 base64 站点转换:

    enter image description here

    关于web-services - 如何在 Jmeter 中对 Base64 的附件进行编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36552265/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com