Automation Testing

QuickTest Pro How to Test a REST Service

By Test Guild
  • Share:
Join the Guild for FREE

In this video, I show a quick example on how to use QuickTest Pro 11 and WinHttp to test a REST service. The QTP web-addin is not needed for this example.

Below is the code used for this example:

Set myRestBody = XMLUtil.CreateXMLFromFile("C:\body.xml") 
restRequest = myRestBody.ToString
url ="http://localhost:24240/HPFlights_REST/FlightOrders/"
contentType ="text/XML"
'1) Create reference to the WinHTTP request com object
 Set oWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1") 
 '2) Open a HTTP connection to a HTTP resource 
 oWinHttp.Open "POST", url, False
 '3) Add a HTTP request headers for endpoint and conent type
 oWinHttp.setRequestHeader "Content-Type", contentType  oWinHttp.setRequestHeader "SOAPAction", url
'4) Send a HTTP request to the HTTP server with the header and body info
oWinHttp.Send restRequest
'5) Get response
 response = oWinHttp.ResponseText
'6) Close object reference 
Set oWinHttp = Nothing
'7) print the response
print response
A bearded man with blue glasses and a black-and-white jacket smiles at a microphone in a studio setting.

About Joe Colantonio

Joe Colantonio is the founder of TestGuild, an industry-leading platform for automation testing and software testing tools. With over 25 years of hands-on experience, he has worked with top enterprise companies, helped develop early test automation tools and frameworks, and runs the largest online automation testing conference, Automation Guild.

Joe is also the author of Automation Awesomeness: 260 Actionable Affirmations To Improve Your QA & Automation Testing Skills and the host of the TestGuild podcast, which he has released weekly since 2014, making it the longest-running podcast dedicated to automation testing. Over the years, he has interviewed top thought leaders in DevOps, AI-driven test automation, and software quality, shaping the conversation in the industry.

With a reach of over 400,000 across his YouTube channel, LinkedIn, email list, and other social channels, Joe’s insights impact thousands of testers and engineers worldwide.

He has worked with some of the top companies in software testing and automation, including Tricentis, Keysight, Applitools, and BrowserStack, as sponsors and partners, helping them connect with the right audience in the automation testing space.

Follow him on LinkedIn or check out more at TestGuild.com.

  1. hi joe,
    i have a xml, public key and a private key. i would like to know if i can digitially sign this xml and then send it to a webservice using qtp. not the service test.
    thank you

  2. shaan » Hi Shaan – I’m not sure how to do this. Have you taken a look at the AddAttachment or AddHeader Methods of the WebService object? Good Luck ~Joe

  3. Hi Joe
    thanks for you code. I have to authenticate before
    ‘4) Send a HTTP request to the HTTP server with the header and body info
    oWinHttp.Send restRequest
    How do i do that?

    Thanks
    Sarma

  4. Sarma » Hi Sarma – you might want to try using the SetCredentials method. The SetCredentials method sets credentials to be used with an HTTP server, whether it is a proxy server or an originating server.

    Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0

    WinHttpReq.SetCredentials “yourusername”, ourHTTPREQUEST_SETCREDENTIALS_FOR_SERVER

    For more info check out: http://msdn.microsoft.com/en-us/library/aa384058(v=vs.85).aspx

    Cheers,
    Joe

  5. How to POST the REST webservice request which is available in xml format. Please do the needful on this.

  6. Hi Joe

    if “contentType = application/x-www-form-urlencoded”, the request format should be Post Form, and how to send a request?

    Susu

  7. Hi Joe,

    Very thank you for you Video on how to test Rest Service. I did what you suggested. I am getting Response in Json format, But I need it in XML format. Is I am doing any mistakes? Please let me know your comments?
    For your information, I am getting response in XML format when i send the request through SOUP 3.6.1 service.

  8. hi Joe,

    I am trying to test rest service.In response i am gettng internal error.please advice

  9. M Sivateja » Hi what rest service are you trying to test? Also is there anything else in the error msg or is it just internal error?

  10. hi

    while running the same example i am getting error at line number 5… Invalid character
    Line (5): “contentType =”application/json””.

    can u please help on this

  11. Hi Joe,

    How can I send Authorization Key and Secret with my REST service?

    Thanks,
    Balu

  12. Hi Joe,
    I am trying to automate rest services API using QTP, which returns the response in JSON format. What are the changes to be done on the above sample script to perform a Search operation ( GET). I have modified the content type= “application/json”. Any help on this is highly appreciated.

    Thanks in Advance,
    Jas

  13. Hi Joe,

    As Jas mentioned, I am testing REST service which returns JSON format. What changes need to be done for ‘GET’ operation

  14. Hi Jas,

    Did you come to know how to modify the code to receive the response. Please help me.

    Thanks!!

  15. Hi Joe,

    One question, If I want to parameterize my rest request for different data inputs, how can we do that with above script.

    Thanks,
    Ranjith

  16. I was trying to automate this restful service but when i use this code i was getting “The remote server returned an error: (407) Proxy Authentication Required” … Does anyone have code to resolve this issue?

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

5 Top Model Context Protocol Automation Tools (MCP Guide 2025)

Posted on 04/09/2025

What is Model Context Protocol (MCP) Model Context Protocol (MCP) is an open ...

What is TDD (Test Driven Development)

Posted on 04/05/2025

What is Test-Driven Development (TDD)? Test-Driven Development is a software development approach that ...

The Best Open Source API Testing Tools for 2025

Posted on 04/01/2025

Here is my list of the best open source API testing tools for ...