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

查看:31
本文介绍了如何在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. 将以下行放入后处理器的脚本"区域:

  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$

    如果您需要部分响应,而不是整个响应,您可以根据Regular Expressions JMeter 用户手册章节

    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天全站免登陆