我试图从以下URL中的code =(。+)中提取代码值。
http://localhost:8080/playground2/oauth2client?code=6ad65435-cd4e-3c3c-a257-4bc0c9092897
任何人都知道确切的bean shell表达式仅获得代码值
答案 0 :(得分:0)
在Beanshell中,您可以使用Matcher
使用以下代码import java.util.regex.Pattern;
import java.util.regex.Matcher;
Pattern p = Pattern.compile("code=(.+)");
Matcher m = p.matcher("http://localhost:8080/playground2/oauth2client?code=6ad65435-cd4e-3c3c-a257-4bc0c9092897");
if (m.find()) {
System.out.println(m.group(1));
}
答案 1 :(得分:0)
请注意,since JMeter 3.1 it is recommended to use JSR223 Test Elements with Groovy language and __groovy() function适用于所有脚本,因此请考虑尽快使用Groovy。
关于您自己的问题,目前尚不清楚URL来自何处,因此假设使用__groovy() function,请友好地找到一个通用解决方案:
${__groovy(("http://localhost:8080/playground2/oauth2client?code=6ad65435-cd4e-3c3c-a257-4bc0c9092897" =~ "code=(.+)")[0][1],)}
演示:
参考文献: