I am trying to calculate a variable value in order to send that value as a header in JMETER, something like this:
Date timestamp = new Date();
String now = DateUtils.toIso8601Date(timestamp);
vars.put("timestamp", "hello");
I put this code in a beanshell preprocessor and then used the following syntax in a header manager hoping to send the timestamp as a header:
However the value of the variable is not being replaced in the header. Further down the line I want to be able to use code to calculate an HMAC signature and send it as a header. Is there any way to do this in jmeter? use a script to calculate a header value and then send it? I've done this in postman with the pre-req scripts but I don't see a similar mechanism in jmeter. Thanks
This DateUtils.toIso8601Date
function is not something I'm aware of, it's neither present in Java SDK nor in libraries which come with JMeter. If you're using a custom library which provides this function you will need to:
Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting especially when it comes to "heavy" tasks like cryptographic operations so consider migrating. More information: Beanshell vs. JSR223 vs. Java For JMeter: Complete Showdown