Search code examples
web-servicesresthttpvb6winhttp

Invoking a RESTFul WebService using WinHttp


I am totally new with VB6 and REST architecture. Nevertheless I would like please to know if there is any HelloWorld example for a REST Client which invokes a RESTFul webService using Windows HTTP Services API. Many thanks in advance.


Solution

  • Here's the solution :

    Sub SendAsynchMessage()
    
    Dim objHTTP As New WinHttp.WinHttpRequest
    Dim doc As New MSXML2.DOMDocument
    Dim root As MSXML2.IXMLDOMNode
    Dim success As Boolean
    Dim str As String
    On Error GoTo ErrorHandler
    success = doc.Load(App.Path & "\flow.xml")
    Set root = doc.selectSingleNode("/root")
    str = CStr(root.childNodes.Item(0).xml)
    URL = "http://ipAddress:8081/messageAsynch"   
    objHTTP.Open "POST", url, False
    objHTTP.SetRequestHeader "Content-Type", "text/xml; charset=utf-8"
    objHTTP.Send (str)
    Debug.Print objHTTP.Status
    Debug.Print objHTTP.ResponseText
    Exit Sub
    ErrorHandler:
    Dim E As ErrObject: Set E = Err
    
    End Sub
    

    The "flow.xml" file could look like in this case :

    <?xml version="1.0" encoding="utf-8" ?>
    <root>
      <!-- your xml flow to be send via http -->
    </root>