我有一个非常标准的函数可以将一些 XML 字符串数据发布到远程 WCF 服务并提取结果。它工作正常,但无法扩展到“大量”数据(在这种情况下为 138KB。)
' 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
当我使用Microsoft.XMLHTTP
我得到error 7 out of memory
.
当我使用MSXML2.XMLHTTP.6.0
我得到object doesn't support this property or method
.
在任何一种情况下,发送一个少于一千个字符的小字符串都可以完美地工作。
这是我尝试不同方式发送字符串时得到的结果:
- 使用
oHttp.send(sContent)
:即使是小的 POST 也会失败Invalid procedure call or argument Runtime error 5
。 - 使用
oHttp.send sContent
:即使是小的 POST 也会失败Invalid procedure call or argument Runtime error 5
。
最后oHttp.send CStr(sContent)
奏效了。谢谢大家的建议,因为我迷路了。