在Jmeter中处理HTTP请求中的cookie [英] Handling cookies in HTTP request in Jmeter

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

问题描述

我有一个Jmeter加载项目,需要检索2个cookie值,然后在其他请求中重新发送它们.

I have a Jmeter load project the requires retrieving 2 values of cookies and resend them in the other requests.

这是我的项目测试计划:

Here is my project test plan:

-Test Plan
-Thread Group
-Login request
-Payment page
-Payment history page
-HTTP Cookie Manager
-HTTP Header Manager
-View Results Tree

Cookie数据: JSESSIONID = 0000SZb55xyLAaqLlDzumq_PpIw:-1; XSRF-TOKEN = a684e233-648e-4219-ae21-25fb362e232d

Cookie Data: JSESSIONID=0000SZb55xyLAaqLlDzumq_PpIw:-1; XSRF-TOKEN=a684e233-648e-4219-ae21-25fb362e232d

cookie管理器已成功从登录请求中接收到cookie数据,并在第二个请求(付款"页面)中发送了cookie数据,但是在第三个请求中(付款历史"页面)仅发送了JSESSIONID,我不知道为什么第二个cookie不会在第三个请求中发送.

The cookie data is received successfully from the login request by cookie manager and sent in the second request (Payment page) but in the third request (Payment history page) only JSESSIONID is sent and I don't know why the second cookie is not sent in the third request.

推荐答案

很可能您没有在

Most probably you are not getting this cookie in Set-Cookie response header for second request therefore it doesn't get picked up by the cookie manager. If your application expects the cookie in 3rd request it might be your application issue.

作为解决方法,您可以将Cookie值存储到 JMeter变量中,以供日后使用再利用.

As a workaround you can store the cookie value into a JMeter Variable for later re-use.

  • 将下一行添加到 user.properties 文件(位于JMeter安装的"bin"文件夹中) CookieManager.save.cookies = true
  • 重新启动JMeter以获取财产
  • 就是这样,现在您应该可以在需要的地方将cookie值引用为${COOKIE_XSRF-TOKEN},例如,添加另一个 HTTP Cookie管理器作为第三个请求的子项(根据XSRF_TOKEN和其他cookie(如果需要的话)
  • Add the next line to user.properties file (lives in the "bin" folder of your JMeter installation CookieManager.save.cookies=true
  • Restart JMeter to pick the property up
  • That's it, now you should be able to refer cookie value as ${COOKIE_XSRF-TOKEN} where required, for example add another HTTP Cookie Manager as a child of the 3rd request (according to Scoping Rules "local" cookie manager will override the "global" one) and define XSRF_TOKEN and other cookies if needed there)

请参见在有关如何在JMeter测试中处理Cookie的更多信息,请参见JMeter 文章.

这篇关于在Jmeter中处理HTTP请求中的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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