问题
I have this string :
Location →/cochise/workflow/5c46e69364ddf300013412b5
How do I extract the final hexadecimal code using jmeter?
回答1:
Add a Regular Expression Extractor
post processor as a child of your request with below configurations:
- Apply to:
Main sample and sub-samples
- Field to check:
Response Headers
- Reference Name:
myVar
- Regular Expression:
Location: .+\/(.*?)\n
- Template:
$1$
- Match No:
1
- Default Value:
NOT_FOUND
Now you can use jmeter variable ${myVar}
which contains hexadecimal value. You can add view results tree and debug sampler at thread group level to make sure you are extracting the right value.
References
- Regular expressions from Jmeter user manual.
- Using regex with jmeter
回答2:
The easiest is going for the Regular Expression Extractor
- Add Regular Expression Extractor as a child of the request which returns the above header
Configure it as follows:
for your convenience here is the textual form of the regular expression:
/cochise/workflow/(.*)
That's it, you should now be able to access the extracted value as
${foo}
where required.Also be aware that you can test your regular expressions via
RegExp Tester
mode of the View Results Tree listener. This approach in conjunction with i.e. Dummy Sampler can greatly speed up scripts development process as you will not have to re-run the entire scenario in order to test an extractor:
来源:https://stackoverflow.com/questions/54305507/extract-location-from-response-header-with-jmeter