编辑:随着我等待答案并进行外部研究,这个问题已经改变。我已经重新表述了标题,问题实际上是我正在寻找 MSXML2 的替代方案(即使这意味着编写套接字代码)。 问题的原始正文留在这里供引用,并帮助将来进行类似搜索的人。
In VBA, using MSXML2 object, is there a way to get access to the streaming data while readyState = 3, as it comes in?
I am using the
OnReadyStateChange
method, but I don't seem to have access toresponseText
until readyState is 4. When readyState is 3, there doesn't seem to be any data.Is there any way in VBA to have access to the HTTP streaming response while it is coming in? Another method I could use in MSXML2, or a better (free, distributable) object to use to make "AJAX" calls?
More information: If I try to read
responseStream
(orresponseText
), the error description is:
The data necessary to complete this operation is not yet available.
Second edit, more information: This link basically says that this is expected behavior in the
INTERACTIVE
(3) state:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms753800(v=vs.85).aspx
所以我肯定在寻找“还有其他选择吗?”回答。
最佳答案
这是我编写的一段旧代码,用于使用 WinInet API 读取 block ,它不是异步的,但它在每 512 个字节后公开一个读取缓冲区(我添加了 Debug.Print "READ "和 lngTotalBytesRead 来说明) - http://pastebin.com/6uMhkBUF
据我所知,它工作正常,但我不得不对其进行一些修复。
您需要在
HTTPGetUAString
中删除对App.
的调用(最初是 VB6),因此只需HTTPGetUAString = "MyThing"
或类似内容。If (lngContentLen = 0&) then lngContentLen = (BUFF_LEN * DUMMY_BUFF_MULTIPLIER)
是剩余的;你可以删除该行。 (随后,如果 lngContentLen 为零,则大小提前未知)
关于ajax - 用于 VBA 检索大型 HTTP 请求的 MSXML2 的替代方案,并可访问 ReadyState 3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13744301/