如何在Jmeter中生成cookie并将其发送到请求中 [英] How to generate a cookie and send it in a request in Jmeter

查看:324
本文介绍了如何在Jmeter中生成cookie并将其发送到请求中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Jmeter还是很陌生,因此无法确定以下内容: 我正在测试需要在标题中发送有效cookie的Web服务.我有一个用于验证用户名和密码的端点url.如何针对url验证凭据并提取用户的cookie并将其发送到Jmeter中用于请求的标头中?

I am fairly new to Jmeter and hence having trouble figuring out the following: I am testing a web service that needs a valid cookie to be sent in header. I have an endpoint url against which the userid and password validates. How do I validate the credentials against the url and extract the cookie for the user and send it in header for the request in Jmeter?

推荐答案

JMeter提供了 HTTP Cookie Manager 会自动处理Cookie,因此在大多数情况下,除了将HTTP Cookie Manager添加到您的

JMeter provides HTTP Cookie Manager which automatically handles cookies so in the majority of cases you don't need to do anything apart from adding the HTTP Cookie Manager to your Test Plan

但是在某些情况下,即在某些 CSRF实现中,您需要添加请求标头,包含先前的响应特定的cookie值.在这种情况下,您应该采取以下行动:

However in some cases, i.e. in some CSRF implementations you need to add a request header holding previous response specific cookie value. In that case you should be acting like:

  1. 将下一行添加到 user.properties 文件(位于JMeter的"bin"文件夹中

  1. Add the next line to user.properties file (lives in JMeter's "bin" folder

CookieManager.save.cookies=true

  • 重新启动JMeter以拾取该属性.上面的设置告诉" JMeter将cookie值存储为 JMeter变量,其前缀为COOKIE_ .因此,例如,如果您的Cookie的名称为foo,则可以访问其值为${COOKIE_foo}
  • 添加 HTTP标头管理器并将其设置为使用以下方法发送所需的标头${COOKIE_foo}作为值(用您的实际Cookie名称替换foo)
  • Restart JMeter to pick the property up. The above setting "tells" JMeter to store cookie values as JMeter Variables prefixed by COOKIE_. So for example if you have cookie with the name of foo you will be able to access its value as ${COOKIE_foo}
  • Add HTTP Header Manager and set it up to send the desired header using ${COOKIE_foo} as a value (replace foo with your actual cookie name)
  • 更多详细信息:使用HTTP Cookie JMeter经理

    这篇关于如何在Jmeter中生成cookie并将其发送到请求中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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