XMLHTTP和“拒绝访问”错误 [英] XMLHTTP and "Access denied" error
问题描述
我正在尝试使用MS XMLHTTP COM检索HTTP文档的内容。我确实复制了以下示例代码,但是即使这样也不起作用,并且在send方法调用中使用 EOLEException错误访问被拒绝失败。
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 :(
推荐答案
Google执行基于位置的重定向,有时涉及重定向到另一个域。 XMLHTTP
不喜欢而且,从浏览器之外的本地脚本(如VB,Delphi等)运行时,似乎 XMLHTTP
不允许访问远程服务器。 a href =http://social.msdn.microsoft.com/Forums/en-US/netfxjscript/thread/876d8f68-9051-4c50-997b-e018eb1cd6d1 =noreferrer>本次讨论,< a href =http://social.msdn.microsoft.com/Forums/eu/xmlandnetfx/thread/1abda1ce-e23c-4d0e-bccd-a323aa7f2ea5 =noreferrer>这个讨论和此文档。
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, Delp etc) outside of a browser. See this discussion, this discussion, and this documentation.
这篇关于XMLHTTP和“拒绝访问”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!