Jeffrey Lee
Jeffrey Lee

Reputation: 51

How do you delete a header completely from a request using groovy?

I need to be able to do what the red x button does, but in a groovy script:

enter image description here

I tried the following script, but it looks like the empty strings only clear the header and its value, but not delete it:

import com.eviware.soapui.support.types.StringToStringMap 

def headers = new StringToStringMap()
headers.put("","")

It seems like there is still a header according to the tab:

enter image description here

Looks like the error is in line 4

enter image description here

enter image description here

enter image description here

Upvotes: 1

Views: 2642

Answers (1)

Rao
Rao

Reputation: 21389

Please use below groovy script. All you need to do is provide the Rest Request test step's name in the below :

import com.eviware.soapui.support.types.StringToStringMap    
//Define / change the step name for which headers to be removed.
def step = 'REST Request'
def nextRequest = context.testCase.testSteps[step]?.httpRequest
nextRequest?.requestHeaders = [:]

EDIT: based on OP's comments

Change from:

nextRequest?.requestHeaders = [:]

To

nextRequest?.requestHeaders = [:] as StringToStringMap

Upvotes: 2

Related Questions