You can dynamically construct your authorization header using Beanshell PreProcessor as follows:
-
Add empty HTTP Header Manager as a child of your request which requires authorization
-
Add Beanshell PreProcessor as a child of the same request with the following code:
import org.apache.jmeter.protocol.http.control.Header; sampler.getHeaderManager().add(new Header("Authorization","Bearer " + vars.get("BEARER")));
This will construct fully dynamic header using BEARER
variable.
sampler
is a shorthand to HTTPSamplerProxy class which gives access to parent Sampler instancevars
is the instance of JMeterVariables class which allows read/write access to all JMeter variables available within the bounds of current context (usually current Thread Group)
See How to use BeanShell: JMeter’s favorite built-in component guide for more details on Beanshell scripting and kind of Beanshell cookbook.