用PHP读取XML文件
我试图用PHP读取XML文件,但我遇到了这个错误,不知道我做错了什么用PHP读取XML文件,php,xml,file-get-contents,Php,Xml,File Get Contents,我试图用PHP读取XML文件,但我遇到了这个错误,不知道我做错了什么 Warning: file_get_contents(username:password@http://services.mobile.de/1.0.0/ad/search) [function.file-get-contents]: failed to open stream: No such file or directory in /www/htdocs/*******/mobile.php on line 11 Fa
Warning: file_get_contents(username:password@http://services.mobile.de/1.0.0/ad/search) [function.file-get-contents]: failed to open stream: No such file or directory in /www/htdocs/*******/mobile.php on line 11
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /www/htdocs/*******/mobile.php:12 Stack trace: #0 /www/htdocs/w00f6d79/mobile.php(12): SimpleXMLElement->__construct('') #1 {main} thrown in /www/htdocs/*******/mobile.php on line 12
我的代码是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mobile.de</title>
</head>
<body>
<?php
$url = "username:password@http://services.mobile.de/1.0.0/ad/search";
$xml = file_get_contents($url);
$data = new SimpleXMLElement($xml);
echo $data->children('ad', true)->ad->vehicle->class->children()->children('resource', true)->local-description;
?>
</body>
</html>
mobile.de
服务器上找不到您试图获取的文件
1) 服务器上找不到您请求/重定向到的文件
2) 从服务器返回的任何内容都不是有效的XML内容
请检查文件的位置和服务器配置。
用户名:password@http://services.mobile.de/1.0.0/ad/search
不是有效的URL。一些HTTP客户端理解http://username:password@services.mobile.de/1.0.0/ad/search
,但身份验证应该在HTTP头中,而不是URL中
$authorization = base64_encode('username:password');
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Authorization: Basic ".$authorization."\r\n"
)
);
$context = stream_context_create($options);
$data = file_get_contents(
'http://services.mobile.de/1.0.0/ad/search', false, $context
);
url
用户名:password@http://services.mobile.de/1.0.0/ad/search
不可访问。文件获取内容
对信誉一无所知。“用户名”和“密码”是通配符。是本地文件还是远程文件?@Micheled'Amico它可以使用流包装器从多个来源读取,包括http。