问题
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; Path=/msf; Expires=Fri, 05 Dec 2064 09:25:44 UTC; HttpOnly
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
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.
回答1:
You should be able to get the cookie value without having to extract it using regex.
- 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:
回答2:
Try this regular expression,
Auth\=(.*); Path
with remaining settings which you have used.
In this I am expecting you need only authcode value, As Authocde label is constant no need to extract it.
来源:https://stackoverflow.com/questions/27313024/unable-to-capture-alpha-numeric-data-using-regular-expression-extractor-in-jmete