所以我一直试图从PlaystationNetwork API获取一些数据,
http://www.psnapi.com.ar/ps3/api/psn.asmx/getPSNID?sPSNID=jameslfc19
所以我一直在使用这段代码
<?php
//Get Username
$username = $_GET["u"];
// Passing the XML
$psnxml = @simplexml_load_file('http://psnapi.com.ar/ps3/api/psn.asmx/getPSNID?sPSNID=' .$username);
$psnname = $psnxml->PSNId->Avatar;
echo $psnname;
?>
Run Code Online (Sandbox Code Playgroud)
这绝对没有输出..
我正在使用@,否则我得到了(是的我知道,但我认为即使XML文档有500个Internel服务器错误,它仍然会获取数据)
Warning: simplexml_load_file(http://psnapi.com.ar/ps3/api/psn.asmx/getPSNID?sPSNID=jameslfc19) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /Applications/XAMPP/xamppfiles/htdocs/Sigs/PSN2.php on line 6
Run Code Online (Sandbox Code Playgroud)
做这个的最好方式是什么?我假设我忽略了@的错误导致了问题.
在simlexml_load_file php.net上的评论中,我发现了以下内容.没有经过测试,但值得一试.
sen at aliencreations dot com 17-Mar-2011 10:59如果您发现使用simplexml_load_file()收到500个错误,但是您可以通过浏览器手动访问xml/rss提要,则您的脚本可能被用户代理阻止嗅探器.
在xml调用之前添加此代码以解决此问题
Run Code Online (Sandbox Code Playgroud)<?php ini_set("user_agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); ini_set("max_execution_time", 0); ini_set("memory_limit", "10000M"); $rss = simplexml_load_file($feed_url); ?>