我有一个非常标准的功能,可以将一些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)
工作了。谢谢大家的建议,因为我迷路了。
答案 0 :(得分:2)
尝试围绕sContent取出Str()并使用括号按值传递它,例如
oHttp.send(sContent)
或者至少使用CStr()失败 - Str()应该将数字转换为字符串。