我正在尝试将格式正确的cxml文件发布到远程服务器URL。我的代码建立连接但在实际的SEND命令上失败。我不一定是VBA的新手,但我是POSTING xml的新手,并向这个论坛发布了帮助请求。希望我做得对。
我得到状态= 200并且回复#34;缺少XML"当我发帖。看来XML数据实际上并没有上传到远程服务器
remoteurl = "http://myremoteurl.com/incoming"
FileNameXML = XML file read into a string variable
FileNameSource = fullpath & filename of XML file="C:\xmls\test00001.xml"
' I am calling the following function & storing response
xmlresp = HTTPPostTXT(remoteurl, FileNameXML, FileNameSource)
Function HTTPostTxt(ByVal sUrl As String, xmlText As String, ByVal xmlname As String)
Set XMLHTTP = CreateObject("Microsoft.XMLHTTP")
XMLHTTP.Open "POST", sUrl, False
Set xmldom = CreateObject("Microsoft.XMLDOM")
xmldom.LoadXML xmlText
xmldom.Validate
' xmldom.xml does not error out but XML file does not get sent/uploaded
XMLHTTP.send xmldom.xml
MsgBox XMLHTTP.Status & " " & XMLHTTP.responseText ' Return Status # & reponseText
' I am storing response and status for troubleshooting
If XMLHTTP.Status <> 200 Then
Sheets(Shtname).Cells(iRow, 6).Value = XMLHTTP.responseText
HTTPPostTxt = "Failure"
Else
Sheets(Shtname).Cells(iRow, 6).Value = XMLHTTP.responseText
HTTPPostTxt = "Accepted"
End If
End Function
(1)我正在寻找有关发送XML字符串数据的错误的帮助。这假设这就是我无法发送数据的原因。以下是我将XML文件读入String变量
的方法Function XMLFileString(ByVal XMLFileName As String) As String
Dim text, textline As String
Open XMLFileName For Input As #1
Do Until EOF(1)
Line Input #1, textline
text = text & textline
Loop
Close #1
XMLFileString = text
End Function
(2)更改SEND命令以发送实际文件(使用fullpath&amp; filename)是一个选项。不知道该改变什么。我想我需要将LOADXML命令更改为LOAD并使用文件名。