Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLHTTP and "Access denied" error

I'm trying to retrieve a content of HTTP document with MS XMLHTTP COM. I did copied the following sample code but even this does not work and fails with EOLEException error 'Access is denied' at send method call.

uses
  MSXML, ComObj, ActiveX;

procedure TForm1.Button1Click(Sender: TObject);
var
  httpDoc: XMLHTTP;  // IXMLHTTPRequest
begin
    httpDoc := CreateOleObject('MSXML2.XMLHTTP') as XMLHTTP;
  try
    httpDoc.open('GET', 'http://www.google.com/index.html', False, EmptyParam, EmptyParam);
    httpDoc.send('');  // <-- EOLEException 'Access is denied'
    if (httpDoc.readyState = 4) and (httpDoc.status = 200) then
      ShowMessage(httpDoc.responseText);
  finally
    httpDoc := nil;
  end;
end;

I really don't know what am I doing wrong :(

like image 788
David Unric Avatar asked Dec 30 '11 00:12

David Unric


1 Answers

Google does location-based redirections, and sometimes that involves redirecting to another domain. XMLHTTP does not like that. Also, it seems XMLHTTP does not allow access to remote servers when running from a local script (such as from VB, Delphi, etc) outside of a browser. See this discussion, this discussion, and this documentation.

like image 99
Remy Lebeau Avatar answered Oct 23 '22 08:10

Remy Lebeau