Xmlhttp 请求引发拒绝访问错误 [英] Xmlhttp request is raising an Access Denied error
问题描述
以下 Excel 宏向此网页发出 xmlhttp 请求以在第二阶段检索一些值,直到一段时间前在 VBA 中都可以正常工作:
The following Excel macro, which is making an xmlhttp request to this webpage to retrieve some values at a second stage, has worked normally in VBA until some time ago:
Sub WebReq()
Link = "http://it.finance.yahoo.com/q?s=^FCHI&ql=10" & str(rnd())
Set htm = CreateObject("htmlFile")
Set RequestWeb = CreateObject("msxml2.xmlhttp")
With RequestWeb
.Open "GET", "" & Link & "", False
.send
htm.body.innerhtml = .responsetext
End With
End Sub
现在,在调用方法时:
.send
对象 msxml2.xmlhttp 引发以下错误:
of the object msxml2.xmlhttp is raising the following error:
Run-time error '-2147024891 (80070005)'
Access is denied.
我一直在网上寻找,但所有类似的主题都没有得到答复.任何人都可以向我解释这个错误是什么意思,如果有什么办法可以修复它,甚至只是解决它?
I've been looking on the web but all the similar threads are never answered. Can anyone explain me what this error means, and if there's any way I could fix it or even just work around it?
注意:变量'Link'末尾的随机字符串已被添加以强制页面重新加载,因为脚本正在检索实时值,因此每次都应加载.
Note: the random string at the end of the variable 'Link' has been added to force the page reloading, since the script is retrieving real-time values and so it should be loaded every time.
附加信息:在寻找解决方案时,我现在注意到,即使我结束运行并重新启动,链接的随机部分也始终产生相同的值:
Additional information: while looking for a solution, I'm noticing now that the random part of the link is yielding always the same value even when I end the running and restart again:
Link = http://it.finance.yahoo.com/q?s=^FCHI&ql=10 .7055475
为什么会这样?rnd()
不应该在每次调用时产生一个介于 0 和 1 之间的新随机值吗?
Why is this happening? Shouldn't rnd()
yield a new random value between 0 and 1 at every call?
推荐答案
使用
CreateObject("MSXML2.ServerXMLHTTP.6.0")
从本地计算机发出的标准请求禁止访问不受 IE 信任的站点.MSXML2.ServerXMLHTTP.6.0
是服务器端对象,不执行这些检查.
The standard request fired from a local machine forbids access to sites that aren't trusted by IE. MSXML2.ServerXMLHTTP.6.0
is the server-side object, that doesn't perform those checks.
这篇关于Xmlhttp 请求引发拒绝访问错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!