我正在尝试从它的url打印一个页面的xml源内容:
echo file_get_contents("http://eur-lex.europa.eu/legal-content/FR/TXT/XML/?uri=CELEX:32012R0823
但是,出现错误消息:
警告:file_get_contents (http://eur-lex.europa.eu/legal-content/FR/TXT/XML/?uri=CELEX: 32012 r0823)
请问出什么事了?获取源XML的最佳方法是什么?
如果您在源页面中声明了try ob_start()函数,那么它可能会被header阻塞。
问题解决了!我公司的代理人对此负有责任。为了解决这个问题,我安装了CNTLM(本地代理:命令行工具)。因此,您必须使用公司代理的信息更新cntlm.ini,并运行以下命令:
cntlm -I -f -c {path of cntlm.ini}
然后,php脚本:
$aContext = array(
'http' => array(
'proxy' => "localhost:{port(in cntlm.ini find 'listen', in my case it is 3128)}",
'request_fulluri' => True,
'userid'=>"{username}",
'password'=>"{password}"
)
);
$context = stream_context_create($aContext);
$content = file_get_contents({your target url string}, 0, $context);
echo $content;