0
当我尝试使用file_get_contents时出现以下错误消息: (URL已更改)。PHP:file_get_contents无法打开流:HTTP请求失败! HTTP/1.0 401未授权
Warning: file_get_contents(http://user:[email protected]/test/test.xml?cmd=show&user=*) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized in /srv/www/htdocs/phonebook.php on line 50
如果我调用URL,我可以在浏览器中看到XML文件。它之间没有空格。但是,我不明白。为什么它不起作用。 PHP版本是5.3.17。我应该使用cUrl吗?
的语法是:
$xml_echo = "http://".$user.":".$pass."@".$ip .$url;
echo $xml_echo;
$xml_string = file_get_contents($xml_echo);
另外的问题,我得到的,并可能与所描述的一个做的是,我得到一个错误,当我尝试使用:
$xml = new SimpleXMLElement(utf8_encode($xml_string));
我也试过使用:simplexml_load_string
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /srv/www/htdocs/phonebook.php:55 Stack trace: #0 /srv/www/htdocs/phonebook.php(55): SimpleXMLElement->__construct('') #1 {main} thrown in /srv/www/htdocs/get_pbx_phonebook.php on line 55