有没有一种方法可以为jmeter中的所有发布请求添加请求参数? [英] Is there a way to add a request parameter for all post requests in jmeter?

查看:485
本文介绍了有没有一种方法可以为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.

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

  1. Add Beanshell PreProcessor to your Test Plan (at the same level as your HTTP Requests)
  2. Put the following code into the PreProcessor's "Script" area:

sampler.addArgument("token", "token_value");

用您的实际数据替换tokentoken_value

Replace token and token_value with your actual data

运行测试时,将在每个采样器之前执行Beanshell PreProcessor,并将参数添加到每个

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

参考文献:

  • 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中的所有发布请求添加请求参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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