通过API导出XML文件

时间:2018-06-04 12:21:50

标签: excel vba excel-vba api post

如何通过API上传XML工作表详细信息。虽然我使用下面给出的VBA代码,但我得到了一个错误,比如认证错误。

Sub HTTPPost()
  'create an xml object
    Dim oXML As Object
    Set oXML = CreateObject("MSXML2.DOMDocument")

    oXML.async = False

    Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")

    oHTTP.setOption(2) = (oHTTP.getOption(2) - SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS)
    oHTTP.Open "POST", "https://isp-api-is1-test.prg-dc.com/gateway/CustomerOrder/1.0/CustomerOrder", False
    oHTTP.setRequestHeader "Username_IT", "onLwEa54"
    oHTTP.setRequestHeader "Content-Type", "application/xml"
    oHTTP.setRequestHeader "Accept", "application/xml"
    oHTTP.setRequestHeader "APIKey", "163c4821-5a6c-499e-9a9c-ca8b5659e530"
    oXML.Load ("C:\Users\nypaul\Downloads\API_CustomerOrder_AFR_V1_52.xml")
    oHTTP.send oXML
End Sub

1 个答案:

答案 0 :(得分:0)

我无法访问该地址,是否有效?

否则这里是一般构造(对于注释来说代码太长)

Option Explicit

Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
Sub HTTPPost()
  'create an xml object
    Dim oXML As Object, oHTTP As Object
    Set oXML = CreateObject("MSXML2.DOMDocument")
    oXML.async = False
    Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    oHTTP.SetOption(2) = (oHTTP.GetOption(2) - SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS)
    oHTTP.Open "POST", "https://isp-api-is1-test.prg-dc.com/gateway/CustomerOrder/1.0/CustomerOrder", False
    oHTTP.setRequestHeader "Username_IT", "onLwEa54"
    oHTTP.setRequestHeader "Content-Type", "application/xml"
    oHTTP.setRequestHeader "Accept", "application/xml"
    oHTTP.setRequestHeader "APIKey", "163c4821-5a6c-499e-9a9c-ca8b5659e530"
    oXML.Load ("C:\Users\nypaul\Downloads\API_CustomerOrder_AFR_V1_52.xml")
    oHTTP.send oXML
End Sub