Search code examples
http-headersjmeterbeanshell

JMeter : How do I Remove local HTTP Header Manager from each Requests in the Thread Group?


Here is a link to image: https://i.sstatic.net/fIg3R.png

I have local Header manger for each request. I also have Global one. [Please look at the image] I want to remove local Header manager for all requests.

I tried it by creating a preprocessor and writing "sampler.getHeaderManager().removeHeaderNamed("HTTP Header manager");" inside it. But, It's not working. Because of this, It cannot authenticate credentials.

I also tried "sampler.getHeaderManager().remove(0)". This didn't work too. remove(1) ignores the global header manager.


Solution

  • Here is my suggestion. Care must be taken care while following the below steps. I follow this trick to replace dynamic values.

    1. Take a backup of your JMeter script.

    2. Open the script in the notepad++.

    3. Find the Header Manager tags. It goes something like this <hashTree><HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true"><collectionProp name="HeaderManager.headers"/></HeaderManager><hashTree/>

    If you have many Header Manager Name and its name unique, you can use regular expression in notepad++.

    Reg ex syntax in notepad++

    <hashTree><HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="(.+)" enabled="true"><collectionProp name="HeaderManager.headers"/> </HeaderManager><hashTree/>

    Reg Ex in Notepad++

    1. Replace it with empty value using Find and Replace.

    While replacing, please take care of <hashtree></hashtree> tags, any conflicts will result in corruption in the script. Use Test Plan Check Tool plugin to validate your test plan. Please visit this link to know more https://jmeter-plugins.org/wiki/TestPlanCheckTool/

    1. Save it and open in JMeter.

    Before

    Before

    After

    After