Perform HTTP Post from within Excel and Parse Results

前端 未结 4 1575
感动是毒
感动是毒 2020-12-14 23:26

I have access to an API. The API takes an XML post as input and then returns an XML response with the relevant data.

I want to

  1. Send the HTTP Post to
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 00:02

    If you need to send your input xml as the message body here is how you can do it. You may need to add more or change the Request headers to get it to work for you.

    Using the DOMDocument object make it easy to work with your xml documents.

    Add a project references to;

    • Microsoft WinHTTP Services, version 5.1
    • Microsoft XML, v6.0

    Example:

    Dim xmlInput As String
    xmlInput = ""
    
    Dim oXmlHttp As MSXML2.XMLHTTP60
    Set oXmlHttp = New MSXML2.XMLHTTP60
    
    oXmlHttp.Open "POST", serviceURL, False, "UserName", "Password"
    oXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    oXmlHttp.setRequestHeader "Connection", "Keep-Alive"
    oXmlHttp.setRequestHeader "Accept-Language", "en"
    
    oXmlHttp.send xmlInput
    
    Debug.Print oXmlHttp.responseText
    
    Dim oXmlReturn As MSXML2.DOMDocument60
    Set oXmlReturn = New MSXML2.DOMDocument60
    oXmlReturn.loadXML oXmlHttp.responseText
    

提交回复
热议问题