Forum Discussion

larsn's avatar
larsn
Contributor
11 years ago

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:

...
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('')
No RepliesBe the first to reply