2010-09-21 22 views

回答

1

與此玩弄周圍直到@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); 
+0

非常好!多謝你們! – steamboy 2010-09-22 00:00:46

2

你需要欺騙代理得到它接受請求。

使用此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); 
+0

現在我明白了。謝謝!這工作正常,但我得到這個錯誤上面警告:curl_setopt()期望參數2是很長的字符串在/Users/ginocortez/phpprojects/testing/xmlcurl.php第4行 – steamboy 2010-09-21 23:59:12