首页 > 解决方案 > 无法将 JMeter 令牌值作为 cookie 发送

问题描述

0

我在运行在我的笔记本电脑上运行良好但在服务器虚拟机(Windows 和 Linux)上运行良好的脚本时遇到问题。

我测试的应用程序中的一些模块通过 Cookie 与客户端进行通信。在访问这些功能时,承载身份验证令牌预计将与请求标头一起作为 cookie 发送。这些主要是浏览器上的 javascript 事件。

我笔记本电脑上的 JMeter 5.3 成功地将这些带有 / 在服务器名称字段中的 cookie 值发送到应用程序服务器,并且还获得了成功的 HTML 响应。但是在 Linux/Windows 服务器上,它会给出非法字符错误(正确)。

然后我决定直接在 Windows Server 上开发脚本。当我在路径中删除并添加 / 而不是主机名时,未发送 cookie 值(令牌)并且应用程序服务器引发身份验证错误。如果我添加 2 个正斜杠,它适用于某些端点,它适用于 3 个正斜杠。///。某些端点与 // 一起使用,如果您仅选择“自动重定向”。如果您选择“Follow Redirects”,应用程序会再次引发身份验证错误。开发人员指责 JMeter 的请求不正确,但没有给我更多信息。

还尝试在 jmeter.properties 中设置 CookieManager.save.cookies=true

有人可以帮助解决这种奇怪的 JMeter 行为吗?

谢谢, 帕莎

标签: cookiesjmeter

解决方案


If you're talking about "Domain" field of the HTTP Cookie Manager:

enter image description here

then you can tell your developers that they should stop blaming JMeter for sending incorrect requests but they should rather read RFC 6265 followed by RFC 1034, once done they should quit their developer jobs and become rickshaws.

If you want to know more how does JMeter handle cookies the best way is enabling debug logging for the HTTP Cookie Manager by adding the next line to log4j2.xml file:

<Logger name="org.apache.jmeter.protocol.http.control" level="debug" />

and next time you start JMeter you will see way more information regarding cookies extraction and manipulation in the jmeter.log file.


推荐阅读