Forum Discussion

VTest's avatar
Occasional Contributor
9 years ago

How to add addtional HTTP header to all the Rest Requests

Hi All,

I have project with about 20 rest services , it was working fine until last week without any issue, With the recent changes in the code All the Rest requests requests addtional HTTP header, "Accept-Language: en;q=0.8" is there any way to directly add this header to all the Rest requests

Or do i need to add this manually to all Requests.


Any suggestions would help. Thank you in advance 

4 Replies

  • kondasamy's avatar
    Regular Contributor

    I have a script, which would add the additional header field without disturbing the existing headers. Please feed this script in a Groovy test step and execute. This would apply the new header for all the REST request within the project.


    //Get through all the test steps in the project
        suite ->
                           if (it.getValue().config.type.equals("restrequest"))
                                   //Get the headers of the current teststep
                                   def headers = it.getValue().getHttpRequest().getRequestHeaders()
                                   def list = []
                                   //Append the new header to the existing list
                                   headers["Accept-Language"] = list;
                                   //Set the updated header list
    }"************************************************\n Done ! New Header Appended to all teststeps!\n************************************************ ")

    Hope this answers your need!





    Did my reply answer your question? Give Kudos or Accept it as a Solution to help others, Thanks. ↓↓↓

  • nmrao's avatar
    Champion Level 3


    This can be done in both automated and manual ways.


    Looks like, you already know how to add the header to each request manually.


    In order to be able to do it in automated fashion, it requires 'Events' feature which is available  out-of-the-box in Pro editions[ReadyAPI/SoapUI Pro].


    However, for open source edition, there is an extension available here, please follow the instructions.



    Once you followed the instructions, need to add the code given below to in %SOAPUI_HOME%/scripts/RequestStepBeforeSubmit.groovy file to add the custom http header. So that above extension would execute this groovy file before submitting the request.


    Here is code that goes into above groovy file:


    if (submit.request.testStep instanceof com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep) {
    	submit.request.requestHeaders['Accept-Language'] = ['en;q=0.8']

    The mentioned header will be added run time for each Rest Request Test step.

    If you do not want to add any header you may just comment it out or add conditionally as well.


     The whole above will just  act as similar to(Pro) SubmitListener.beforeSubmit() and add the above code.






    • anand7892's avatar
      Occasional Contributor

      I want to add a header in all the rest Request in my project

      The value that i need to put in the header is getting generated by login API.


      I am using Pro Version

      Can you suggest me steps to follow


      • nmrao's avatar
        Champion Level 3
        1. Please open a question in SoapUI Pro forum rather than reviving an old thread.

        2. You can use Events feature, Submit beforeStep and add the code.