I am trying to post a well-formed cxml file to a remote server url. My code makes the connection but fails on the actual SEND command. I am not necessarily a newbie to VBA but I am a newbie to POSTING xml and posting help request to this forum. Hope I did it right.
I get status = 200 and a response of "Missing XML" when I post. It appears that the XML data is not actually getting uploaded to remote server
remoteurl = "http://ift.tt/15tQuwl"
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) I am looking for help on what I am doing wrong with sending the XML string data. This is assuming that this is why I can't SEND data. Here is how I read the XML file into String variable
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) Changing the SEND command to send the actual file (using fullpath & filename) is an option. Not sure what to change. I think I need to change the LOADXML command to a LOAD and use the filename.
No comments:
Post a Comment