gpt4 book ai didi

java - Jmeter BeanShell - 访问响应数据 - Beanshell 错误?

转载 作者:行者123 更新时间:2023-12-01 20:55:42 24 4
gpt4 key购买 nike

我的 Beanshell 后处理器中有这段代码

String line;
String[] words;

line = SampleResult.getResponseMessage(); log.info(msg);

words = line.split("*");

log.info("Here We are");

for (int i = 0; i < words.length; i++) {
log.info(words[i]);
}

这是我遇到的错误

2017/02/21 14:23:31 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of:
String line; String[] words; line =
SampleResult.getResponseMessage(); log.inf . . . '' : Attempt to
resolve method: getResponseMessage() on undefined variable or class
name: SampleResult 2017/02/21 14:23:31 WARN -
jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script
org.apache.jorphan.util.JMeterException: Error invoking bsh method:
eval Sourced file: inline evaluation of:
String line; String[] words; line = SampleResult.getResponseMessage(); log.inf . . . '' : Attempt to resolve method: getResponseMessage() on undefined variable or class name: SampleResult

最佳答案

严格来说,要消除错误,您需要将 SampleResult 替换为 prev

prev - (SampleResult) - gives access to the previous SampleResult

( source )

因此要解决异常:

line = prev.getResponseMessage(); 
log.info(line);

您始终可以在对象本身中看到对象为您提供的变量列表:

enter image description here

但是,如果我理解正确的话,您希望从采样器获取数据而不是响应消息。因此,您可能需要使用 getResponseDataAsString() 而不是 getResponseMessage()

所以大家在一起:

line = prev.getResponseDataAsString(); 
log.info(line);

关于java - Jmeter BeanShell - 访问响应数据 - Beanshell 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42378336/

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