Forum Discussion

Adagio's avatar
Adagio
Frequent Contributor
6 years ago

Pass JSON request body in a PUT Request

Hello,

 

In one of my programs, I'm trying to send a put request and capture the response.

For PUT requests, I have a URI and JSON request body. 

 

I also have to parameterize 4 fields in the JSON request. I don't know if test complete would support such a solution.

I don't want to have JSON request body embedded in my code because of it's size, and also for the reusability of the code. 

 

Is there a way I can keep the JSON request body in an external file, reference that file in the program, pass reuqired paramenters as the args, and send the http reuqest using aqHttp Object ? 

 

Any thoughts would be helpful

 

Thank you

Al

 

  • Hi Al,

     

    While it depends on the specifics of your case/program, in general you should be able to do what you need with the help of the aqHTTP.CreateRequest() method.

    To read the content of JSON body from the file you may use the aqFile object provided by TestComplete.

    See TestComplete documentation for more details and code examples.

     

  • Hi Al,

     

    Yes, you should be able to do this using the aqHttpRequest.SetHeader() method.

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Al,

     

    While it depends on the specifics of your case/program, in general you should be able to do what you need with the help of the aqHTTP.CreateRequest() method.

    To read the content of JSON body from the file you may use the aqFile object provided by TestComplete.

    See TestComplete documentation for more details and code examples.

     

    • Adagio's avatar
      Adagio
      Frequent Contributor

      Thanks Alex! I'm wondering whether an authentication token can be passed in the http request as well?

       

      Thank you

      Al  

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi Al,

         

        Yes, you should be able to do this using the aqHttpRequest.SetHeader() method.