Trying to load xml from a url using msxml:
Setting .async
to false (default is true) causes E_ACCESSDENIED
error trying to .load from a url
var
doc: DOMDocument60;
begin
doc := CoDOMDocument60.Create;
doc.async := False; // Default is True
doc.load('https://www.treasury.gov/ofac/downloads/sdn.xml');
Why would it cause an E_ACCESSDENIED
exception?
The workaround is easy:
var
http: IServerXMLHTTPRequest;
doc: DOMDocument60;
begin
http := CoServerXMLHTTP60.Create;
http.open('GET', 'https://www.treasury.gov/ofac/downloads/sdn.xml',
False, EmptyParam, EmptyParam);
http.send(EmptyParam);
doc := http.ResponseXML as DOMDocument60;
Of course i'm not asking about a workaround. I'm asking why a workaround is needed in the first place.
Interestingly, while IServerXMLHTTPRequest
works, and only supports synchronous loading, asking the DOMDocument60
to use ServerHTTPRequest
synchronously does not work:
var
doc: DOMDocument60;
begin
doc := CoDOMDocument60.Create;
doc.async := False; // Default is True. Must be false if we use ServerHTTPRequest
doc.setProperty('ServerHTTPRequest', True);
doc.load('https://www.treasury.gov/ofac/downloads/sdn.xml'); E_ACCESSDENIED
It's strange that:
Which is my question: Why does it fail?
It's not using Wininet:
And even if it was using WinInet, the Internet Explorer option:
is unchecked.
So what's the problem?
It's a known Won't Fix
bug in XMLHTTPRequest; which is based off WinINET.
The solution is to use ServerXMLHttpRequest; which is based off WinHTTP.
Which is why WinHTTP was originally created, to fix the bugs in WinInet.