1

I am using classic asp/vbscript to load a RSS. In this case the URL should start with https rather than http so I get the error : Access is denied. How can I check if the target url is accessible and healthy and the use it?

Set xmlDOM = CreateObject("MSXML2.DOMDocument.6.0")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("http://iqna.ir/fa/rss/services/36")

I have tried to wrap it inside if/then but obviously will result in the same error:

if (xmlDOM.Load("http://iqna.ir/fa/rss/services/36")) then
   'Proceess the RSS content
end if
Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82
  • Use an XHR and check the Response StatusCode. Then use the XML `LoadXML()` on a successful `Response` object. – user692942 Apr 11 '20 at 09:03
  • Loading any resource over HTTP the process is the same, request it, process the response and parse the response. This is universal across all HTTP resources. Once you know the response is valid, store the `ResponseText` and use `LoadXML()` to take the serialised data and parse it into an XML structure. It’s how the internet wotks. – user692942 Apr 11 '20 at 09:09
  • How should I request for http xml resource rather than `xmlDOM.Load`? @Lankymart – Ali Sheikhpour Apr 11 '20 at 09:17
  • 1
    Pretty sure I explained that in my previous comment. – user692942 Apr 11 '20 at 09:29

1 Answers1

0

xmlDOM.Load directly loads the target resource and has no method to check the validity of target url. Use MSXML2.XMLHTTP to check tha target validity:

function testUrl(url)
    Set o = CreateObject("MSXML2.XMLHTTP")
    on error resume next
    o.open "GET", url, False
    o.send
    if o.Status = 200 then testUrl = True
    on error goto 0
    set o=nothing
end function

Set xmlDOM = CreateObject("MSXML2.DOMDocument.6.0")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
url="http://iqna.ir/fa/rss/services/36"
if testUrl(url) then
    xmlDOM.Load(url)
end if

Regarding the comment from Lankymart this is the way to consume the MSXML2 response directly without a new request by chaning Load to loadXML:

url="http://iqna.ir/fa/rss/services/36"
Set o = CreateObject("MSXML2.XMLHTTP")
on error resume next
o.open "GET", url, False
o.send
if o.Status = 200 then 
    Set xmlDOM = CreateObject("MSXML2.DOMDocument.6.0")
    xmlDOM.loadXML(o.responseText)
end if
on error goto 0
set o=nothing
Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82
  • 2
    If you do that you're making two requests instead of one. Return the resource (in this case XML) with the XHR then load it into the XML document using `LoadXML()`. That way you make one request not two. – user692942 Apr 11 '20 at 10:20