Apache Jmeter提取__RequestVerificationToken并使用它登录 [英] Apache Jmeter extracting __RequestVerificationToken and using it to log in

查看:163
本文介绍了Apache Jmeter提取__RequestVerificationToken并使用它登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用Jmeter来自动执行此过程,但是我无法自动执行登录过程.我使用以下正则表达式提取__RequestVerificationToken <input name="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9+=/\-\_]+?)">

I am currently using Jmeter to automate this process however I am not able to automate the login process. I have used the following regular expression to extract the __RequestVerificationToken <input name="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9+=/\-\_]+?)">

然后我尝试登录时继续请求令牌

I then proceed to request the token when attempting to log in

但是,在运行测试时,我收到的响应码为500.调查请求数据时,令牌未正确提取

When running the test however I am receiving Response code of 500. When investigating the request data the token is not being pulled correctly

推荐答案

记住不要使用正则表达式来解析HTML数据.开发和维护用于处理HTML代码的正则表达式确实令人头疼,而且正则表达式对任何标记更改(换行符,额外空间,属性顺序更改等)都非常敏感,因此我建议您考虑切换到 CSS/JQuery提取器代替.相关配置将非常简单:

Remember not to use regular expressions to parse HTML data. It is a real headache to develop and maintain regular expressions dealing with HTML code, moreover regular expressions are very sensitive to any markup change (line break, extra space, attributes order change, etc.) so I would recommend considering switching to CSS/JQuery Extractor instead. The relevant configuration will be as simple as:

  • 参考名称:任何有意义的内容,tok都可以
  • CSS/JQuery表达式:input[name=__RequestVerificationToken]
  • 属性:value
  • Reference name: anything meaningful, tok will be fine
  • CSS/JQuery Expression: input[name=__RequestVerificationToken]
  • Attribute: value

这样,您将拥有可靠而可靠的方法来提取__RequestVerificationToken值.

This way you will have robust and reliable way of extracting the __RequestVerificationToken value.

演示:

请参见如何在JMeter中使用CSS/JQuery提取器有关更多信息的文章.

See How to Use the CSS/JQuery Extractor in JMeter article for more information.

这篇关于Apache Jmeter提取__RequestVerificationToken并使用它登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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