1

如何在 VBS 中完成之前异步读取 XMLHTTP?下面的示例(如果睡眠时间不够长,则会出现“完成此操作所需的数据尚不可用”错误)使用一个大的 Wikipedia 页面,但最终我想将其用于无限的网页/流永远不会完成加载。那么,有没有一种简单的方法来修改这个示例以尽早获得部分 HTTP 响应?

strFileURL = "https://en.wikipedia.org/wiki/Algorithm"  ' or any big webpage

Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")   ' all of these xmlhttp options have no "streaming success"
' Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
' Set objXMLHTTP = CreateObject("Microsoft.XmlHttp")
' Set objXMLHTTP = Createobject("MSXML2.XMLHTTP.3.0")
' Set objXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.6.0")

objXMLHTTP.open "GET", strFileURL, true
objXMLHTTP.send()

' Is there something other than ResponseText to avoid error and get partial result below (i.e., read html like a stream)?
WScript.Sleep 500                   ' need to play with this time to try to cause mystate1=3 below
mystate1 = objXMLHTTP.ReadyState    ' should be 3
myscan = objXMLHTTP.ResponseText    ' CAUSES ERROR if mystate1 < 4 (comment this line out to avoid error)
WScript.Sleep 1000
mystate2 = objXMLHTTP.ReadyState    ' should be 4
myscan = objXMLHTTP.ResponseText

MsgBox(mystate1)
MsgBox(mystate2)
MsgBox(myscan)

Set objXMLHTTP = Nothing
4

1 回答 1

0

这是不可能的,至少通过使用 XMLHTTPRequest 是不可能的。如文件所述,在请求完成之前既不可用responseText也不可用。responseBody

于 2013-05-24T10:08:26.903 回答