Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xmlHttp help

Status
Not open for further replies.

SuperKing2007

Programmer
Feb 6, 2007
1
US
I am sending an xml document using MSXML2.XMLHTTP40, posting to a url but i dont know how to read back the response. I am getting blank as response whereas it should be an xml document.
here's my code
Dim sDestinationURL As String
Dim sUsername As String
Dim sPassword As String
Dim dtStart As Date
' Dim sXMLStringData As String
Dim lRetryCount As Long
Dim bSuccess As Boolean
Dim sLastKnownStatus As String
Dim sDataReturned As String
Dim XMLHttpRequest As MSXML2.XMLHTTP40

Dim myDom As DOMDocument
Set myDom = New DOMDocument

With myDom
.async = False
.Load "C:\SPI.xml"
End With
sXMLStringData = myDom.xml

' Now the pipe is open from the Get, lets post some data.
If (bSuccess = True) Then
bSuccess = False 're-use bool
lRetryCount = 0 'reuse the count
Do While bSuccess = False And lRetryCount < 3
Set XMLHttpRequest = New MSXML2.XMLHTTP40

XMLHttpRequest.open "post", sDestinationURL, False, sUsername, sPassword

XMLHttpRequest.setRequestHeader "Authorization", "Basic" & (sUsername & ":" & sPassword)
XMLHttpRequest.setRequestHeader "Synchronous", "False"
XMLHttpRequest.setRequestHeader "Content-Type", "text/xml"
XMLHttpRequest.setRequestHeader "Accept-Language", "en-US"

dtStart = Now
XMLHttpRequest.send sXMLStringData

Do While XMLHttpRequest.readyState <> 4
DoEvents

TimeOut = DateDiff("s", dtStart, Now)
If TimeOut >= 9 Then 'Wait 9 seconds
Exit Do
End If
Loop
If (XMLHttpRequest.readyState = 4) Then
sLastKnownStatus = XMLHttpRequest.statusText & " - " & XMLHttpRequest.statusText
sDataReturned = XMLHttpRequest.responseText & vbCrLf & vbCrLf & "Error: " & Err.Number & ":" & Err.Description
bSuccess = True
Dim xml_res As MSXML2.DOMDocument

Set xml_res = New MSXML2.DOMDocument
Set xml_res = XMLHttpRequest.responseXML
xml_res.save "C:\testing.xml"

Debug.Print "Success " & Now
Else
sLastKnownStatus = "Timeout"
sDataReturned = "Timeout Error: " & Err.Number & ":" & Err.Description
XMLHttpRequest.abort
Debug.Print "Failure " & Now
End If

Set XMLHttpRequest = Nothing
lRetryCount = lRetryCount + 1
Loop
End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top