如何解析 Jmeter 响应并发出新请求 [英] How to parse Jmeter response and make a new request
问题描述
我正在使用 jMeter 来测试 Tomcat 应用程序.我需要解析 jMeter 响应并发出第二个请求.第一个响应如下所示:
I'm using jMeter to test a Tomcat application. I need to parse the jMeter response and make a second request. The first response looks like this:
<responseData class="java.lang.String"><html>
<body>
ERROR=0
MSG=N/A
FILELIST=1555;1340778737370;1526545487;
VERSION=1.002
URL=https://192.168.100.46/updserver/download?action=signature_download&token=
INTERVAL=0
</body>
</html>
</responseData>
我需要提取FILELIST"和URL"变量并将它们注入到一个新的 URL 中:
I need to extract the "FILELIST" and "URL" variables and inject them into a new URL:
https://192.168.100.46/updserver/download?action=signature_download&token=1555;1340778737370;1526545487;
我知道有一些后处理器可以做到这一点,但不知道如何去做.顺便说一句,第二个请求将从 Tomcat servlet 下载一些文件,有没有办法让 jMeter 只下载流而不写入物理文件?这样我就可以对我的 servlet 进行负载性能测试.
I know there is some post-processor to do that, but no clue how to do it. BTW, the second request will download some file from the Tomcat servlet, is there a way to let jMeter just download the stream but without writing to a physical file? So that I could do a load performance test against my servlet.
推荐答案
好的,你已经知道如何从你的回复中提取 url,我在我之前的回答中描述了如何:
Ok so you already know how to extract url out of your response, I described how in my previous answer :
https://stackoverflow.com/a/11188349/169277
但在这里我将对此进行扩展.所以你有你的采样器,你已经有了 ${url}
.现在你需要 FILELIST
并组装新的 url.
But here I'll just expand on that. So you have your sampler and you already got ${url}
. Now you need FILELIST
and assemble new url.
假设您已经准备好请求和 url 提取器.添加一个新的正则表达式提取器
.
Assuming you already have request and url extractor in place. Add a new Regular expression extractor
.
右键单击请求采样器 ->后处理器 ->正则表达式提取器
Reference Name : FILELIST
Regular Expression : FILELIST=(S+)
Template : $1$
Match No. (0 for Random): 1
所以现在您有 1 个请求采样器和 2 个正则表达式提取器.您需要添加额外的后处理器才能组装新的 url.
So now you have 1 request sampler and 2 regular expression extractors. You need to add additional post processor to be able to assemble the new url.
右键单击请求采样器 ->后处理器 ->BSF 后处理器
从Script language
下的语言下拉列表中选择beanshell
并在大字段Script:
中粘贴:
Choose the beanshell
from the language droplist under the Script language
and in the big field Script:
paste this :
vars.put("NEW_URL", "${__javaScript('${url}'.replace('
','${FILELIST}'))}");
现在您可以在测试中进一步使用 ${NEW_URL}
.
And now you have ${NEW_URL}
to use further in your tests.
解决问题的方法总是不止一种,这个班轮看起来很丑,但它确实起到了作用.
在我的测试中,结果如您所愿(调试采样器):
In my test the result is as you requested (Debug Sampler) :
url=https://192.168.100.46/updserver/download?action=signature_download&token=
FILELIST=1555;1340778737370;1526545487;
NEW_URL=https://192.168.100.46/updserver/download?action=signature_download&token=1555;1340778737370;1526545487;
我想我不明白您如何命名变量.但最终结果是您在问题中描述的结果.请参阅工作示例附带的 .jmx 测试:
I think I don't understand how you name your variables. But the end result is the one you described in your question. Please see the .jmx test attached with working example :
http://www.filefactory.com/file/1q7nfitmh4qd/n/so_11309469_jx
这是一个 jmeter .jmx 文件,适用于 2.6+ 版本的 jmeter
It's a jmeter .jmx file working with 2.6+ version of jmeter
这篇关于如何解析 Jmeter 响应并发出新请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!