如何在jmeter中的变量中保存响应 [英] How to save response in a variable in jmeter

查看:565
本文介绍了如何在jmeter中的变量中保存响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jmeter在服务器上执行负载测试. 在我的一个发帖请求中,我在响应中收到一个唯一的ID. 我需要在以下发布请求中将此ID作为参数发送. 我是jmeter的新手,不知道如何执行此操作. 帮助将不胜感激.

I am performing load testing on my server using jmeter. In one of my post requests, I receive a unique id in the response. I need to send this id as a parameter in the following post requests. I am new to jmeter and don't have any idea how to do this. Help would be really appreciated.

推荐答案

如果您需要将整个响应存储到变量中,请执行以下步骤:

If you need to store the whole response into a variable - take the following steps:

  1. Beanshell PostProcessor 添加为请求的子代,该请求可返回响应正在寻找
  2. 将以下行放入PostProcessor的脚本"区域:

  1. Add Beanshell PostProcessor as a child of the request which returns response you're looking for
  2. Put the following line into the PostProcessor's "Script" area:

vars.put("response", new String(data));

  • 在需要的情况下将提取的值引用为${response}

    请参见如何使用BeanShell:JMeter最喜欢的内置组件指南,以进一步了解JMeter中的Beanshell脚本

    See How to Use BeanShell: JMeter's Favorite Built-in Component guide to lean more about Beanshell scripting in JMeter


    或者,您可以对正则表达式提取器执行相同的操作,在这种情况下,相关配置将是:


    Alternatively you can do the same with the Regular Expression Extractor, in that case relevant configuration will be:

    • 参考名称:response
    • 正则表达式:(?s)(^.*)
    • 模板:$1$
    • Reference Name: response
    • Regular Expression: (?s)(^.*)
    • Template: $1$

    如果您需要部分响应,而不是全部响应,则可以根据

    If you need a part of response, not the whole response you can amend Regular Expression according to your needs as per Regular Expressions chapter of JMeter's User Manual

    这篇关于如何在jmeter中的变量中保存响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆