Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xmlhttp request is raising an Access Denied error

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

Now, instead, at the call of the method:

    .send

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?

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

Why is this happening? Shouldn't rnd() yield a new random value between 0 and 1 at every call?

like image 483
Matteo NNZ Avatar asked Apr 08 '14 13:04

Matteo NNZ


5 Answers

Use

CreateObject("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.

like image 166
John Lasschuit Avatar answered Nov 06 '22 23:11

John Lasschuit


i found that, in my case, changing http to https fixed the access denied problem. i can only assume that the website somehow made a change and didn't tell anyone

like image 45
Don Avatar answered Nov 06 '22 23:11

Don


access denied is IE issue

internet options > security tab > custom security level > Miscellaneous >Access data sources across domains > enable
like image 6
Saad A Avatar answered Nov 06 '22 23:11

Saad A


Update

Sub WebReq()

link = "http://it.finance.yahoo.com/q?s=^FCHI&ql=10" & Str(Rnd())
Set htm = CreateObject("htmlFile")
Dim objHttp

    Set objHttp = CreateObject("Msxml2.ServerXMLHTTP")
    objHttp.Open "GET", link, False

    objHttp.Send
    htm.body.innerhtml = objHttp.responsetext
    Set objHttp = Nothing
End Sub
like image 2
Rich Avatar answered Nov 07 '22 01:11

Rich


This works for me:

With CreateObject("MSXML2.ServerXMLHTTP.6.0")
  .Open "GET", URL, False
  .Send
  content = .ResponseText
End With
like image 1
Apostolos Avatar answered Nov 07 '22 00:11

Apostolos