无法使用 Beanshell 脚本对数据库进行 HTTPS 调用以写入数据

Unable to Make HTTPS call using Beanshell script to DB to write the data

  1. 我尝试 post 将数据从 post man 和 JMeter HTTP Sampler 导入数据库,我能够 post 成功地获取数据。
  2. 当我尝试在 BeanShell 脚本的帮助下通过 'JSR223 Listener' 模拟相同的调用时,我收到如下错误,

avax.script.ScriptException: Sourced file: eval stream : Typed variable declaration : Method Invocation httpClient.execute : at Line: 20 : in file: eval stream : httpClient .execute ( httpPost )

Called from method: write : at Line: 54 : in file: eval stream : write ( queryString ) Target exception: java.net.ConnectException: Connection timed out: connect in eval stream at line number 20

任何人都可以告诉我为什么这会导致错误,并且应该对开发的脚本进行任何修改或缺少任何导入吗?

查看 Connection timed out 消息你的代码工作得很好或不太好,它只是无法与目标服务器建立连接,没有看到它很难说什么(盲目:你 运行 你的测试是通过企业代理进行的吗?如果是,你的代码将不会遵守 JMeter 代理设置,你将需要执行单独的配置)

同时有几点建议:

  1. 切换到 Groovy language
  2. 勾选Cache compiled script if available

Groovy 是比 Beanshell 更好的脚本选择,因为它能够将脚本编译成字节码,而 Beanshell 解释器每次调用时都会对其进行评估,因此 Groovy 的执行速度会快得多(假设相同的代码)。此外 Groovy 有更好的 Java 支持并提供一些额外的功能。有关详细信息,请参阅 Groovy is the New Black 文章。