0


Jmeter提取协议报文、请求头、请求体、响应体

参看文章:
https://blog.csdn.net/qq_40308101/article/details/125545245
https://www.thinbug.com/q/34918343
https://www.cnblogs.com/peak911/p/9238738.html

1、

  1. prev

(用于后置处理器、断言)

  1. log.info("数据类型:"+prev.getDataType());
  2. log.info("接口地址:"+prev.getUrlAsString());
  3. log.info("请求头信息:"+prev.getRequestHeaders());
  4. log.info("响应头信息:"+prev.getResponseHeaders());
  5. log.info("响应码:"+prev.getResponseCode());
  6. log.info("响应体"+prev.getResponseDataAsString());
  7. log.info("内容类型:"+prev.getContentType());
  8. log.info("媒体类型:"+prev.getMediaType());
  9. log.info("结果文件名:"+prev.getResultFileName());
  10. log.info("线程名称:"+prev.getThreadName());
  11. log.info("请求名称:"+prev.getSampleLabel());
  12. log.info("消息:"+prev.getResponseMessage());
  13. log.info("接口请求结果:"+(prev.isSuccessful()?"成功":"失败"));

2、

  1. sampler

(用于前置处理器)

https://jmeter.apache.org/api/org/apache/jmeter/samplers/Sampler.html

  1. log.info("http请求名:"+sampler.getName());
  2. log.info("接口请求地址:"+sampler.getUrl().getPath());
  3. log.info("接口请求域名:"+sampler.getUrl().getHost());

3、

  1. sampler

(只能用于Bean Shell 断言)https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html

  1. log.info("响应数据:"+SampleResult.getResponseDataAsString());
  2. log.info("响应码:"+SampleResult.getResponseCode());
  3. log.info("接口名称:"+SampleResult.getSampleLabel());
  4. log.info("请求url:"+SampleResult.getUrlAsString());
  5. log.info("请求头请求地址请求体:"+SampleResult.getSamplerData());
  6. log.info("请求头:"+SampleResult.getRequestHeaders());

4、

  1. vars

https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html

  1. #获取变量
  2. vars.get("variable_name")#设置变量
  3. vars.put("variable_name", "variable_value")#删除变量
  4. vars.remove("variable_name");#创建或更新具有不必为字符串的值的变量
  5. vars.putObject("obj",new Object());

本文转载自: https://blog.csdn.net/weixin_43824520/article/details/126768899
版权归原作者 小小白@ 所有, 如有侵权,请联系我们删除。

“Jmeter提取协议报文、请求头、请求体、响应体”的评论:

还没有评论