参看文章:
https://blog.csdn.net/qq_40308101/article/details/125545245
https://www.thinbug.com/q/34918343
https://www.cnblogs.com/peak911/p/9238738.html
1、prev(用于后置处理器、断言)
- prev 提供对当前取样器结果的访问能力
- prev 映射 org.apache.jmeter.samplers 的 SampleResult 类
- 官方文档: https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html
log.info("数据类型:"+prev.getDataType());
log.info("接口地址:"+prev.getUrlAsString());
log.info("请求头信息:"+prev.getRequestHeaders());
log.info("响应头信息:"+prev.getResponseHeaders());
log.info("响应码:"+prev.getResponseCode());
log.info("响应体"+prev.getResponseDataAsString());
log.info("内容类型:"+prev.getContentType());
log.info("媒体类型:"+prev.getMediaType());
log.info("结果文件名:"+prev.getResultFileName());
log.info("线程名称:"+prev.getThreadName());
log.info("请求名称:"+prev.getSampleLabel());
log.info("消息:"+prev.getResponseMessage());
log.info("接口请求结果:"+(prev.isSuccessful()?"成功":"失败"));
2、sampler(用于前置处理器)
https://jmeter.apache.org/api/org/apache/jmeter/samplers/Sampler.html文章来源:https://www.toymoban.com/news/detail-514116.html
log.info("http请求名:"+sampler.getName());
log.info("接口请求地址:"+sampler.getUrl().getPath());
log.info("接口请求域名:"+sampler.getUrl().getHost());
3、sampler(只能用于Bean Shell 断言)https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html
log.info("响应数据:"+SampleResult.getResponseDataAsString());
log.info("响应码:"+SampleResult.getResponseCode());
log.info("接口名称:"+SampleResult.getSampleLabel());
log.info("请求url:"+SampleResult.getUrlAsString());
log.info("请求头请求地址请求体:"+SampleResult.getSamplerData());
log.info("请求头:"+SampleResult.getRequestHeaders());
4、vars
https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html文章来源地址https://www.toymoban.com/news/detail-514116.html
#获取变量
vars.get("variable_name")
#设置变量
vars.put("variable_name", "variable_value")
#删除变量
vars.remove("variable_name");
#创建或更新具有不必为字符串的值的变量
vars.putObject("obj",new Object());
到了这里,关于Jmeter提取协议报文、请求头、请求体、响应体的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!