Search code examples
jmeterbeanshell

how to parse a value in JMeter sampler result


I am unable to calculate the response header size in Jmeter.

I want to calculate the response header size and i tried below option but i was unsuccessful. Option 1: Parse the value returned in Sampler result --> i do not have an inbuilt option. Option 2: Store the response header in a variable and calculate the length using var.length() function. --> since the response header have new line feeds, the .length function did not work.

Can anyone please suggest me to calculate the response header size in bytes.

Thanks in advance,

Regards, Hari


Solution

  • It should be something like:

    prev.getResponseHeaders().size();
    

    JMeter Response Headers Size

    Where prev is a shorthand to SampleResult class instance.


    Be aware that starting from JMeter 3.1 users are encouraged to switch to JSR223 Test Elements and Groovy language for any form of scripting as Groovy:

    • is more Java-compliant including modern language features
    • has enhancements on top of Java SDK
    • has much better performance

    See Apache Groovy - Why and How You Should Use It article for more details