jmeter處理request和response
需求:
同時打印出:請求體(json)和響應體(json)
先給大家看結果:

如下圖:可見請求體和返回體同時打印出來了

實現代碼:
BeanShell PreProcessor
import org.json.*; import org.apache.jmeter.config.*; Arguments args = sampler.getArguments(); // 截獲請求參數部分 Argument arg_body = args.getArgument(0); // 獲取請求body String body = arg_body.getValue(); // 獲取body的值保存成字符串 vars.put("test",body);
BeanShell PostProcessor
import org.json.*; String response = prev.getResponseDataAsString(); JSONObject jsonObject = new JSONObject(response); String reqs = vars.get("test"); log.info("[request]: "+ reqs); //jsonObject.toString(4):格式化輸出為了好看一點 log.info("[response]: "+ jsonObject.toString(4));

浙公網安備 33010602011771號