简体   繁体   English

jmeter提取正则表达式无法获得正确的结果

[英]jmeter extract regular expression not get correct result

This is my html 这是我的HTML

<input name="__RequestVerificationToken" type="hidden" value="A9y6Ndf7Q2XP2Yz6zhaVChoIvpQGUrZRTvu9D_HnHnUcFBVInerxCjU4vpOXQYVhFwnzl-zAzkvtto7BLAVVr">

I want to extract value in jmeter Regular Expression Extractor. 我想在jmeter正则表达式提取器中提取值。 在此处输入图片说明

This is my regx window but when i post it i will not get expected token it is something like this __RequestVerificationToken=%24%7Bauth_token%7D . 这是我的regx窗口,但是当我发布它时,我不会得到预期的令牌,它就像这样__RequestVerificationToken=%24%7Bauth_token%7D

Try using $1$ as a Template, it should resolve your issue. 尝试使用$1$作为模板,它应该可以解决您的问题。

Looking into your request I can see that you're sending %24%7Bauth_token%7D which being decoded looks like ${auth_token} so you use case is not correct. 查看您的请求,我可以看到您正在发送%24%7Bauth_token%7D ,该解码的内容看起来像${auth_token}因此您的用例不正确。

You need 2 requests: 您需要2个请求:

  1. GET request to get the page and extract RequestVerificationToken and store it to auth_token variable. GET请求以获取页面并提取RequestVerificationToken并将其存储到auth_token变量。
  2. POST Request which will use auth_token variable. POST请求将使用auth_token变量。

See Using Regular Expressions in JMeter guide for more details. 有关更多详细信息,请参见《 JMeter指南》中的“ 使用正则表达式”

By the way, you can use combination of Debug Sampler and View Results Tree listener to see if there are any matches. 顺便说一句,您可以结合使用Debug SamplerView Results Tree侦听器来查看是否存在任何匹配项。 It should be more convenient wrt groups and variables. wrt组和变量应该更方便。

In general, it isn't recommended to use Regular Expressions to parse HTML. 通常, 不建议使用正则表达式来解析HTML。 I would suggest to use XPath Extractor instead. 我建议改用XPath Extractor Relevant XPath expression will look like: 相关的XPath表达式将如下所示:

//input[@name='__RequestVerificationToken']/@value

Few things to notice: 几件事要注意:

  • If you page isn't XHTML compliant you'll need to check Use Tidy box in XPath Extractor 如果您的页面不符合XHTML,则需要选中XPath Extractor中的Use Tidy框。
  • JMeter 2.11 provides nice XPath Tester right in View Results Tree Listener JMeter 2.11在View Results Tree Listener中提供了不错的XPath Tester

We need to set the following Regular Expression Extractor values to extract the auth token values 我们需要设置以下正则表达式提取器值以提取auth令牌值

Reference Name : Auth_Token
Regular Expression : <input\sname="__RequestVerificationToken"\stype="hidden"\svalue="(.+)">
Template : $1$
Match No : 1
Default values : NOT FOUND TOKENS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM