larsn
11 years agoContributor
modify HTTP Content-Type header using groovy
This post to make it easier for folks ...
If you need to change the HTTP Content-Type header using groovy scripting, it won't work by modifying the request headers - like the following:
Instead you have modify the media type - just like the UI. In groovy do this:
If you need to change the HTTP Content-Type header using groovy scripting, it won't work by modifying the request headers - like the following:
...
testStep.getTestRequest().setRequestHeaders(headers)
Instead you have modify the media type - just like the UI. In groovy do this:
def tstep = testRunner.testCase.getTestStepByName("REST http call")
tstep.testRequest.setMediaType('application/json')
# to remove the HTTP Content-Type header, run tstep.testRequest.setMediaType('')