Extract Location from Response Header with JMeter

馋奶兔 提交于 2020-03-22 06:35:13

问题


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

  1. Add Regular Expression Extractor as a child of the request which returns the above header
  2. Configure it as follows:

    for your convenience here is the textual form of the regular expression:

    /cochise/workflow/(.*)
    
  3. That's it, you should now be able to access the extracted value as ${foo} where required.

  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!