英文:
Jmeter retrieve specific portion of SamplerData from SampleResult
问题
我正在尝试检索 SampleResult
中 SamplerData
的特定部分。
以下是我的当前输出:
GET https://google.com/
GET 数据:
hello world
[无 cookies]
我想要的是在 GET 数据
部分内的特定 hello world
。
我有以下的 BackendListener
代码:
@Override
public void handleSampleResults(List<SampleResult> list, BackendListenerContext backendListenerContext) {
StringBuilder stringBuilder = new StringBuilder();
String fileName = "C:\\projects\\sampleResults.csv";
try {
list.forEach(sampleResult -> {
stringBuilder.append(sampleResult.getSamplerData());
stringBuilder.append("\n");
});
BufferedWriter out = new BufferedWriter(
new FileWriter(fileName));
out.write(stringBuilder.toString());
out.close();
} catch (IOException e ){
}
}
英文:
I'm trying to retrieve a specific portion of the SamplerData
from the SampleResult
.
Here's my current output:
GET https://google.com/
GET data:
hello world
[no cookies]
What i want is specifically the hello world
inside the GET data
section.
I have the following BackendListener code:
@Override
public void handleSampleResults(List<SampleResult> list, BackendListenerContext backendListenerContext) {
StringBuilder stringBuilder = new StringBuilder();
String fileName = "C:\\projects\\sampleResults.csv";
try {
list.forEach(sampleResult -> {
stringBuilder.append(sampleResult.getSamplerData());
stringBuilder.append("\n");
});
BufferedWriter out = new BufferedWriter(
new FileWriter(fileName));
out.write(stringBuilder.toString());
out.close();
} catch (IOException e ){
}
}
答案1
得分: 0
针对您的情况,似乎您正在尝试提取 HTTP 请求 采样器的主体数据,最简单的解决方案是使用 sampleResult.getQueryString() 函数。
演示:
然而,我未能看出在这里实现自己的后端侦听器的必要性,您可以使用 Flexible File Writer 插件以更快、更简单的方式实现相同的效果。
英文:
For particular your case it seems that you're trying to extract the body data of the HTTP Request sampler the easiest solution would be going for sampleResult.getQueryString() function
Demo:
However I fail to see the need of implementing your own Backend Listener here, you can achieve the same much faster and easier using Flexible File Writer plugin
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论