[英]Get XML source from URL with PHP
我正在尝试使用以下方法从其 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:32012R0823 )
请问有什么问题吗? 获取源 XML 的最佳方法是什么?
如果您在源页面中声明尝试在页面顶部尝试 ob_start() 函数,则它可能会被标题阻止。
我的问题解决了! 我公司的代理人负责。 为了绕过它,我安装了 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;
我希望它会有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.