如何使用PHP simplexml解析此xml頁面 http://evercore:[email protected]/www.sportsbook.com/trends/203.xml?我收到一個錯誤,說它無法加載。繞過經過驗證的XML頁面與PHP解析?
感謝, 小號
如何使用PHP simplexml解析此xml頁面 http://evercore:[email protected]/www.sportsbook.com/trends/203.xml?我收到一個錯誤,說它無法加載。繞過經過驗證的XML頁面與PHP解析?
感謝, 小號
與此玩弄周圍直到@vassilis指出,用戶代理嗅探應用,把它看作是另一種方式來同一個目標,指出去@vassilis。
<?php
$username = 'evercore';
$password = 'david10';
$opts = array(
'http' => array(
'method' => 'GET',
'header' => sprintf("Authorization: Basic %s\r\nUser-Agent: Foobar!", base64_encode($username.':'.$password))
)
);
$context = stream_context_create($opts);
libxml_set_streams_context($context);
$xml = new SimpleXMLElement(
"http://feeds.outgard.net/www.sportsbook.com/trends/203.xml",
null,
true);
var_dump($xml);
非常好!多謝你們! – steamboy 2010-09-22 00:00:46
你需要欺騙代理得到它接受請求。
使用此PHP代碼來獲得結果:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://feeds.outgard.net/www.sportsbook.com/trends/203.xml');
curl_setopt($ch, CURLOPT_GET, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, 'evercore:david10');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
$data = curl_exec($ch);
echo $data;
// Process data with simple XML
curl_close($ch);
現在我明白了。謝謝!這工作正常,但我得到這個錯誤上面警告:curl_setopt()期望參數2是很長的字符串在/Users/ginocortez/phpprojects/testing/xmlcurl.php第4行 – steamboy 2010-09-21 23:59:12
用戶名/密碼看起來不對。 – vassilis 2010-09-21 22:47:45
哦。其evercore不evernote – steamboy 2010-09-21 22:54:01