无法在JMeter中使用正则表达式提取器捕获字母数字数据 [英] Unable to capture alpha numeric data using regular expression extractor in JMeter
问题描述
我正在JMeter中使用正则表达式提取器提取包含以下内容的响应数据:
I am using regular expression extractor in JMeter to extract the response data which contains something like the following:
Set-Cookie:X-Tr-Auth = b1eada98-ffa1-45a3-522e-591a84dd48f2;路径=/msf; Expires = Fri,2064年12月5日09:25:44 UTC; HttpOnly
上面的数据是在用户登录后从服务器发送的,我需要使用上面的身份验证代码来发布JSON正文.
The above data is sent from the server after user logs in, I need to use the above authcode to post a JSON body.
我已将正则表达式提取器设置为以下值:
I have set the regular expression extractor to the following values:
Reference Name: authcode
Regular Expression: Set-Cookie: "(.+?)"
Template: $1$
Match No. : 1
Default Value: 0
每次运行测试,我都会得到0.我在Stack-overflow中看到了类似的问题,但没有令人满意的答案.需要专家的建议.
I am getting 0 every time I run the test. I saw a similar question in Stack-overflow with no satisfactory answer. Need expert advise.
推荐答案
您应该能够获取cookie值,而不必使用正则表达式来提取它.
You should be able to get the cookie value without having to extract it using regex.
- 在 user.properties 文件中添加
CookieManager.save.cookies=true
行,该文件位于JMeter安装目录的/bin文件夹下 - 如果JMeter正在运行,则重新启动它(从文件读取属性不是动态的,并且在加载时执行)
- 在测试计划中添加 HTTP Cookie管理器
- 添加 HTTP标头管理器作为请求的子级需要参数化和配置,如下所示:
- 名称:
Cookie X-Tr-Auth
- 值:
${authcode}
- 名称:
- Add
CookieManager.save.cookies=true
line into user.properties file which lives under /bin folder of your JMeter installation - Restart JMeter if it's running (reading properties from file is not dynamic and performen on load)
- Add a HTTP Cookie Manager to your test plan
- Add a HTTP Header Manager as a child of the request you need to parametrize and configure it as follows:
- Name:
Cookie X-Tr-Auth
- Value:
${authcode}
- Name:
这篇关于无法在JMeter中使用正则表达式提取器捕获字母数字数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!