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