有没有一种方法可以为jmeter中的所有发布请求添加请求参数?

编程入门 行业动态 更新时间:2024-10-12 10:21:26
本文介绍了有没有一种方法可以为jmeter中的所有发布请求添加请求参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要在jmeter中的每个帖子请求中添加一个令牌.我尝试使用Http Request默认值,但是它不起作用.

I need to add a token to each post request in jmeter. I have tried using Http Request defaults but it isn't working.

推荐答案

使用某些脚本可以实现.

It is possible with some scripting.

  • 在测试计划中添加 Beanshell预处理器(与您的HTTP请求)
  • 将以下代码放入预处理器的脚本"区域:

  • Add Beanshell PreProcessor to your Test Plan (at the same level as your HTTP Requests)
  • Put the following code into the PreProcessor's "Script" area: sampler.addArgument("token", "token_value");

    用您的实际数据替换token和token_value

    Replace token and token_value with your actual data

    运行测试时,将在每个采样器之前执行Beanshell PreProcessor,并将参数添加到每个范围内的HTTP请求.

    When you run the test Beanshell PreProcessor will be executed before each sampler and add the parameter to each HTTP Request in scope.

    参考文献:

    • sampler代表HTTPSamplerBase类实例,请参见 HTTPSamplerBase JavaDoc 有关方法和字段的详细信息
    • 如何使用BeanShell:JMeter最喜欢的内置组件-有关通过一些示例在JMeter测试中使用Beanshell脚本的全面信息
    • sampler stands for HTTPSamplerBase class instance, see HTTPSamplerBase JavaDoc for detailed information on methods and fields
    • How to Use BeanShell: JMeter's Favorite Built-in Component - comprehensive information on using Beanshell scripting in JMeter tests with some examples
  • 更多推荐

    有没有一种方法可以为jmeter中的所有发布请求添加请求参数?

    本文发布于:2023-11-17 09:00:18,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1609546.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:参数   方法   jmeter

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!