2010-09-21 5 views

Répondre

1

jouait autour avec jusqu'à ce que @vassilis, voir signalé renifler l'agent utilisateur est appliqué comme une autre façon de le même but, les points aller @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

très bien! Merci les gars! – steamboy

2

Vous devez usurper l'agent pour obtenir d'accepter les demandes.

Utilisez ce code PHP pour obtenir le résultat:

$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

maintenant je comprends. Merci! cela fonctionne bien mais je reçois cette erreur sur le dessus Attention: curl_setopt() attend que le paramètre 2 soit long, la chaîne donnée dans /Users/ginocortez/phpprojects/testing/xmlcurl.php sur la ligne 4 – steamboy