java - 请求登录 JMeter
问题描述
我需要发送一个 sha256 十六进制请求签名以及 http 请求。
从其他问题和答案中,有人建议使用 bean shell 预处理器,但这似乎不再起作用。
还有其他方法可以做到这一点吗?
这是我在 bean shell 预处理器中的代码
import org.apache.commons.codec.digest.DigestUtils;
String api_key = "";
String shared_secret = "";
long timestamp = System.currentTimeMillis()/1000;
String sig = DigestUtils.md5(api_key + shared_secret + timestamp);
vars.put("sig", sig);
log.info("Signature: " + sig);
这就是错误
2020-07-23 10:18:55,694 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.commons.codec.digest.DigestUtils; String api_key = "35yNeSe37 . . . '' : Typed variable declaration
2020-07-23 10:18:55,694 WARN o.a.j.m.BeanShellPreProcessor: Problem in BeanShell script. org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.apache.commons.codec.digest.DigestUtils; String api_key = "35 . . . '' : Typed variable declaration
2020-07
解决方案
- 如果您说需要“sha256 hex”,为什么要使用DigestUtils.md5() ?
- 如果从 JMeter 3.1 开始您应该使用 Groovy,为什么要使用 Beanshell ?
我认为您应该将代码更改为:
vars.put("sig", org.apache.commons.codec.digest.DigestUtils.sha256Hex(api_key + shared_secret + timestamp))
有关 JMeter 中 Groovy 脚本的更多信息,请参阅Apache Groovy - 为什么以及如何使用它一文。
顺便说一句,有__digest() 函数可以让你的生活更轻松:
推荐阅读
- java - 在 Eclipse Che 中调试 Java 测试
- python - 无法使用 json.json(normalize) 从 JSON 中提取数据
- terraform - GKE 节点池状态卡在 PROVISIONING
- javascript - 根据名称收集列表项并存储在数组或对象中
- sql - 如何在同一个 SQLPLUS INSERT INTO 语句中同时使用 SELECT 查询和 RETURNING
- maven - 从 Maven 中的特定存储库下载依赖项
- sql - SQL Oracle - Where 子句中的替换函数
- asp.net-core - .NET 框架 4 应用程序中的 SignalR .net 核心客户端
- java - 本机查询正在返回 Spring Boot 中 #pageable 的所有记录
- c# - ASP.NET MVC:错误 CS0311:类型“XYZ”不能用作泛型方法中的参数“TContext”