如何使用 JMeter 传递随机用户/通行证(用于基本身份验证)?

发布于 2024-09-06 07:50:14 字数 807 浏览 4 评论 0原文

我正在使用 JMeter 对 API 进行压力测试。我已经设置了基本身份验证 - 似乎运行良好。

现在,我正在尝试随机化 JMeter 通过网络传递的凭据。所以,我知道有两种方法可以做到这一点。

  1. 添加自定义 HTTP 标头(通过 HTTP 标头管理器元素),然后将值设置为随机字段(即我从 csv 文件中读取的内容)
  2. 使用HTTP 授权管理器元素 并在其中传递用户名和密码。

现在,如果我尝试使用上面的方法 (1),我需要创建以下标头/数据:-

Authorization: Basic <some Base64 encoded string in the format username:password>

eg.
Authorization: Basic OnVzZXIxOnBhc3Mx

Kewl.简单的。但是该标头值没有通过线路传递:(我可以添加任何其他标头类型,并且它通过线路传递..

嗯..好吧然后..让我们尝试方法(2)。

现在可以了..但我可以仅硬编码在用户名和密码中,我看不到如何传递用户名VARIABLE(即${usernmae}) )或密码VARIABLE(即${password})....如果是硬编码的,那么服务器会正​​确回复正确的页面/数据,

因此..有人可以帮忙吗?

I'm using JMeter to stress test an API. I've got Basic Authentication set up - seems to be working great.

Now, i'm trying to randomize the credentials that JMeter passes across the wire. So, there's two ways I know I can do this.

  1. Add a custom HTTP Header (via an HTTP Header Manager Element) and set then value to the random fields (ie. something I've read in from a csv file)
  2. Use the HTTP Authorization Manager Element and pass in the username and password there.

Now, if I try and use method (1) above, I need to create the following header/data :-

Authorization: Basic <some Base64 encoded string in the format username:password>

eg.
Authorization: Basic OnVzZXIxOnBhc3Mx

Kewl. simple. BUT that header value is not getting passed across the wire :( I can add any other header type and it's passed across the wire..

hmm .. ok then .. lets try method (2).

Now that works .. but I can only hardcode in the username & password. I can't see how I can pass in a username VARIABLE (ie. ${usernmae} ) or a password VARIABLE (ie. ${password} ).... If it's hardcoded, then the server correctly replies with the correct page/data.

so .. can someone please help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话难免假 2024-09-13 07:50:14

我建议尝试以下操作:

  1. 创建一个 HTTP 授权管理器元素
  2. 将用户名和密码设置为变量, ${username} 、 ${password}
  3. 使用您的用户名和密码创建一个 CSV 文件(不要使用标题行)
  4. 创建一个CSV 数据集配置元素,变量名称设置为“用户名,密码”(无引号,逗号后无空格)
  5. 每个线程/循环将从 CSV 文件中读取不同的值。

或者,如果您希望登录时的值是真正随机的,可以使用一些函数来生成随机数或在执行时发送。

I would recommend trying the following:

  1. Create a HTTP Authorization Manager Element
  2. Setup the username and password to be variables, ${username} , ${password}
  3. Create a CSV file with your usernames and passwords (do not use a header row)
  4. create a CSV Data Set Config Element, with the variable names set to "username,password" (no quotes, and no space after the comma)
  5. Each thread/loop will read a different value from the CSV file.

Alternately, if you want the value to be truely random for the login, there are some functions you can use to generate random numbers or send in the time of execution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文