VBscript异步XMLHttp调用

时间:2017-05-12 13:16:27

标签: asynchronous vbscript xmlhttprequest serverxmlhttp

对于我正在尝试进行异步XMLHTTP调用的项目。 我使用以下代码:

soapmessage = _
"<?xml version='1.0' encoding='utf-8'?>"& vbcrlf& vbcrlf & _
"<soap:Envelope"& vbcrlf & _
" xmlns:xsi="&chr(34)&"http://www.w3.org/2001/XMLSchema-instance"&chr(34)& 
vbcrlf & _
" xmlns:xsd="&chr(34)&"http://www.w3.org/2001/XMLSchema"&chr(34)& vbcrlf & _
" xmlns:soap="&chr(34)&"http://www.w3.org/2003/05/soap-
envelope"&chr(34)&">"& vbcrlf & _
" <soap:Body>"& vbcrlf & _
"<notification>"& vbcrlf & _
"   <action>Action</action>"& vbcrlf & _
"   <objectid>333333</objectid>"& vbcrlf & _
"</notification>"& vbcrlf & _
" </soap:Body>" & vbcrlf & _
" </soap:Envelope>"

strEndpoint = "**********"

Set xmlhttp = CreateObject("MSXML2.SERVERXMLHTTP.6.0")
xmlhttp.open "POST", strEndpoint, True
xmlhttp.OnReadyStateChange = doHttpOnReadyStateChange()
xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlhttp.Send soapmessage

Function doHttpOnReadyStateChange()
    If xmlhttp.ReadyState = 4 Then
        'do something
    End If
End Function

当我尝试执行此操作时,我得到以下内容:

  

test.vbs(19,1)Microsoft VBScript运行时错误:类型    不匹配:&#39; xmlhttp.OnReadyStateChange&#39;

任何想法我可能做错了什么? 这是我第一次尝试异步调用,所以我对OnReadyStateChange感到有些困惑

1 个答案:

答案 0 :(得分:2)

它需要一个函数引用,您可以使用GetRef()函数获取它。

xmlhttp.OnReadyStateChange = GetRef("doHttpOnReadyStateChange")

Dirk.R:想补充说这是修复。请记住,陈述的顺序也很重要!