Spartan
Spartan

Reputation: 339

How to read Query Param in Response Location header in Jmeter

I'm load testing my API which requires to authenticate everytime before calling the API. I need to read a query param from HTTP header "Location" and use it in further requests in Jmeter. I tried to use "Regular Expression Extractor" with Location: .+=(.*?)\n but it didn't work. Any ideas how to read a specific variable from response headers?

Location: https://<<SSO_URL>>/authenticate?code=AbCDEfg1&..... --> extract "code"

Upvotes: 0

Views: 657

Answers (2)

Dmitri T
Dmitri T

Reputation: 168157

You need to change your regular expression to something like:

Location:\s* .*=(.*?)&

enter image description here

And make sure to choose Response Headers from the scope:

enter image description here

See Regular Expressions chapter of the JMeter User Manual for more details

Also it might be much easier to use the Boundary Extractor, in this case you will just need to provide the "left" and "right" boundaries and it will fetch everything in-between:

enter image description here

Moreover it works faster and consumes less resources, see The Boundary Extractor vs. the Regular Expression Extractor in JMeter article for more information

Upvotes: 1

Jyoti Prakash Mallick
Jyoti Prakash Mallick

Reputation: 2076

Please try with this, regex for your question is code=([^&]*)

enter image description here

Upvotes: 1

Related Questions