I have a pretty standard function to post some XML string data to a remote WCF service and extract the result. It works fine, but fails to scale to a "large" amount of data (138KB in this case.)
' performs a HTTP POST and returns the resulting message content
Function HttpPost(sUrl As String, sSOAPAction As String, sContent As String) As String
Dim oHttp As Object
'Set oHttp = CreateObject("Microsoft.XMLHTTP")
Set oHttp = CreateObject("MSXML2.XMLHTTP.6.0")
oHttp.open "POST", sUrl, False
oHttp.setRequestHeader "SOAPAction", """http://conducive.com.au/IXpacManagement/" & sSOAPAction & """"
oHttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oHttp.setRequestHeader "Content-Length", Len(sContent)
oHttp.send Str(sContent)
If oHttp.status = 200 Then
HttpPost = oHttp.responseText
Else
MsgBox "An error (" & LTrim(Str(oHttp.status)) & ") has occurred connecting to the server."
HttpPost = ""
End If
Set oHttp = Nothing
End Function
When I use Microsoft.XMLHTTP
I get error 7 out of memory
.
When I use MSXML2.XMLHTTP.6.0
I get object doesn't support this property or method
.
In either case sending a small string of under a thousand characters works perfectly.
Here's what I get when I try different ways of sending the string:
oHttp.send(sContent)
: Even small POSTs fail with Invalid procedure call or argument Runtime error 5
.oHttp.send sContent
: Even small POSTs fail with Invalid procedure call or argument Runtime error 5
.In the end oHttp.send CStr(sContent)
worked. Thank you all for the suggestions because I was lost.
Try taking out the Str() around sContent and just using parentheses to pass it by value, e.g.
oHttp.send (sContent)
or failing that at least use CStr() - Str() is supposed to convert numbers to strings.