Event Management from WinHttpRequest

The program I use runs the .VBS scripts

So, in VBScript , how can you handle the OnResponseFinished event for a WinHttpRequest object ?

Set oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
oHTTP.Open "GET", "http://www.google.com", True
oHTTP.Send
+3
source share
7 answers

Change the third parameter in the method call Opento false. Then put the code that you will have in OnResponseFinishedafter sending the call.

+1
source

, winhttp ( VBScript HTA ). . , , :

Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.Open "GET", "http://www.google.com", True
objHTTP.Send
objHTTP.WaitForResponse 'pauses execution, but does not hang UI
'from now on, execution only takes effect after completion of the response:
msgbox objHTTP.responseText 'an example of what can be done with the response

winhttp script, , . , .

+1

, , VBScript GetRef , , MSXML2.XMLHTTP:

Set oHTTP = CreateObject("MSXML2.XMLHTTP")
oHTTP.Open "GET", "http://www.google.com", True

oHTTP.OnReadyStateChange = GetRef("oHTTP_OnReadyStateChange")

Sub oHTTP_OnReadyStateChange
    ' do something
End sub

oHTTP.Send

, , ..

Set oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
oHTTP.Open "GET", "http://www.google.com", True

oHTTP.OnResponseFinished = GetRef("oHTTP_OnResponseFinished")

Sub oHTTP_OnResponseFinished
    ' do something
End sub

oHTTP.Send

,

: 'oHTTP.OnResponseFinished'

, , , , , MSXML2 ?

COM- - CreateObject, , ,

Set oHTTP = CreateObject("WinHttp.WinHttpRequest.5.1", "oHTTP_")
oHTTP.Open "GET", "http://www.google.com", True

Sub oHTTP_OnResponseFinished
    ' do something
End sub

oHTTP.Send

, - , IWinHttpRequestEvents

0

WScript CreateObject, .

Set oHTTP = WScript.CreateObject(
    "WinHttp.WinHttpRequest.5.1",
    "oHTTP_"
)
0

Windows , , Microsoft, :

Microsoft.XMLHTTP {ED8C108E-4349-11D2-91A4-00C04F7969E8}
MSXML2.XMLHTTP {F6D90F16-9C73-11D3-B32E-00C04F990BB4}
WinHttp.WinHttpRequest.5.1 {2087c2f4-2cef-4953-a8ab-66779b670495}
MSXML2.ServerXMLHTTP {AFBA6B42-5692-48EA-8141-DC517DCF0EF1}

, Microsoft.ServerXMLHTTP, onreadystatechange VBScript. "MSXML2.ServerXMLHTTP" - (, google.com), "Microsoft.XMLHTTP".

Dim xmlhttp ' global so can be accessed in OnStateChange

Sub OnStateChange
    If xmlhttp.readystate = 4 Then
        ' React to xmlhttp.responseText
        MsgBox xmlhttp.responseText
    End If
End Sub

Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "GET", "http://www.google.com/", true
xmlhttp.onreadystatechange = GetRef("OnStateChange")
xmlhttp.send
' do something else whilst xmlhttp is running in the background
MsgBox "Pausing so that OnStateChange can fire!"
0

, this ( ), Err. Microsoft .

0

, , "waitForResponse" "0" - .

IE:

 oHTTP.Open "GET", "http://www.google.com", True
 oHTTP.Send

 Do While oHTTP.waitForResponse(0) = False
   'do stuff while waiting for it to be done

    WScript.Sleep 200 'sleep for 0.2 seconds between checks as not waste CPU 
    DoEvents
 Loop

 'Once the loop is exited, the response is finished
 MsgBox oHTTP.ResponseText
-1

Source: https://habr.com/ru/post/1794868/


All Articles