如何在JMeter中从请求头Referer提取参数值并存储到变量
Got it, pulling specific parameter values from the Referer request header in JMeter is totally doable with built-in post processors. Here are two simple methods to get the job done:
Method 1: Boundary Extractor (Best for Simple Key-Value Pairs)
This is the easiest approach since you don’t need to write regex—just define the boundaries around the value you want.
Add the Boundary Extractor as a child of the sampler that sends the request with your target Referer header:
- Right-click the sampler →
Add→Post Processors→Boundary Extractor
- Right-click the sampler →
Configure for each parameter:
For each value you want to extract (likefundraiserPageID,participantFirstName), set up the extractor like this:- Reference Name: Use the exact parameter name (e.g.,
fundraiserPageID)—this is the variable name where the extracted value will be stored. - Left Boundary: The text immediately before your target value (e.g.,
fundraiserPageID=for the ID). - Right Boundary: The text immediately after your target value (usually
&since parameters are separated by ampersands; if it’s the last parameter, you can leave this empty or use&anyway—it’ll still work). - Match No.: Set to
1(we want the first occurrence of the parameter). - Default Value: Something like
NOT_FOUND(so you’ll know if the parameter is missing).
Example config for
participantFirstName:- Reference Name:
participantFirstName - Left Boundary:
participantFirstName= - Right Boundary:
&
- Reference Name: Use the exact parameter name (e.g.,
Use the variables: Once configured, you can reference the extracted values in subsequent samplers, assertions, or other elements using syntax like
${fundraiserPageID}or${participantFirstName}.
Method 2: Regular Expression Extractor (More Flexible)
If you need more control (like handling complex patterns), use this method with regex.
Add the Regular Expression Extractor as a child of your target sampler:
- Right-click the sampler →
Add→Post Processors→Regular Expression Extractor
- Right-click the sampler →
Configure for each parameter:
- Reference Name: Same as the parameter name (e.g.,
fundraiserPageID). - Regular Expression: Craft a regex to capture the value:
- For numeric IDs like
fundraiserPageID:fundraiserPageID=(\d+)(captures one or more digits) - For text values like
participantFirstName:participantFirstName=([^&]+)(captures any character except&)
- For numeric IDs like
- Template:
$1$(tells JMeter to use the first captured group from the regex). - Match No.:
1(first occurrence). - Default Value:
NOT_FOUND.
- Reference Name: Same as the parameter name (e.g.,
Decode URL-encoded values: If your parameters have URL-encoded characters (like
Test%20TestersonfordisplayName), use JMeter’s__urlDecode()function to get plain text:${__urlDecode(${displayName},)}
Quick Verification Tip
Add a Debug Sampler and View Results Tree listener to your test plan. Run the test, then check the Debug Sampler’s output—you’ll see all your extracted variables and their values, so you can confirm everything is working as expected.
内容的提问来源于stack exchange,提问作者Adnan Ghaffar

