Xmlhttp 请求引发访问被拒绝错误 [英] Xmlhttp request is raising an Access Denied error

查看:31
本文介绍了Xmlhttp 请求引发访问被拒绝错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 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.0server-side 对象,它不执行这些检查.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆