0
votes

In my test using JMeter some attributes are created, see bellow:

-----------------------------7d159c1302d0y0
Content-Disposition: form-data; name="age"
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit


I want to remove attributes:
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit


I try run below script but it didn't worked.

def oldBody = sampler.getArguments().getArgument(0).getValue()
def newBody = oldBody.replaceAll('Content-Type: text/plain; charset=ISO-8859-1','')
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument('',newBody,'')

Someone can help me please?

1
Did you tried sampler.getHeaderManager().removeHeaderNamed("Content-Type");? - user7294900

1 Answers

0
votes

If you're trying to amend the request from the HTTP Request sampler with Use multipart form/data box ticked unfortunately it is not very possible because certain JMeter developers have their own interpretation of "optional" and "may" statements of the RFC 2388 Section 3

The options are in:

  1. Switch to HTTP Raw Request sampler which gives you full control of the request body/headers/etc on TCP protocol level
  2. Build your multipart form/data request manually using HTTP Header Manager and HTTP Request sampler as it's described in Testing REST API File Uploads in JMeter article