[英]How to add the request body data in the post request for JMeter testing using Java code in the non-GUI mode?
[英]How to get body data request in jmeter using java
我想創建插件jmeter,我想使用Java獲取正文數據請求
在jmeter我使用groovy獲得
ctx.getCurrentSampler().getArguments().getArgument(0).getValue();
要么
Arguments argz = ctx.getCurrentSampler().getArguments();
for (int i = 0; i < argz.getArgumentCount(); i++) {
Argument arg = argz.getArgument(i);
String a = arg.getValue();
vars.put("EMAIL",a);
}
但是在Java中我無法在JMeterContext中使用函數getArguments()
ctx
是JMeterContext類的簡寫,您可以通過調用JMeterContextService.getContext()函數從Java請求采樣器訪問它。
用法示例:
給定您的Java Request采樣器放置在HTTP Request采樣器之后,您可以得到其主體,如下所示:
((org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy)org.apache.jmeter.threads.JMeterContextService.getContext().getPreviousSampler()).getArguments().getArgument(0).getValue();
您可以在“ 使用Apache JMeter進行WebSocket測試”文章中找到創建Java請求采樣器的示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.