VBscript Asynchronous XMLHttp Call

烈酒焚心 提交于 2019-12-02 04:58:23

问题


for a project I'm working on I'm attempting to do a Asynchronous XMLHTTP Call. I'm using the following code:

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

When I try to execute this I get the following:

test.vbs(19, 1) Microsoft VBScript runtime error: Type mismatch: 'xmlhttp.OnReadyStateChange'

any idea what I could be doing wrong? It's my first time trying an async call so i'm a bit puzzled with the OnReadyStateChange


回答1:


It needs a function reference which you can get using the GetRef() function.

xmlhttp.OnReadyStateChange = GetRef("doHttpOnReadyStateChange")

Dirk.R: Would like to add that while this is the fix. Keep in mind that the order of the statements also matters!



来源:https://stackoverflow.com/questions/43938709/vbscript-asynchronous-xmlhttp-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!