Bonjour, je cherche une réponse à mon problème depuis hier sans succès 
Cela me parait pourtant simple, mais j'ai du louper quelquechose ...
Voila je débute avec simplexml et je souhaite créer une intéraction avec un API
J'envoie ma requête à l'API avec la commande :
1 2 3 4 5 6 7 8 9 10 11 12 13
| <?php
$fp = fsockopen ("ssl://$host", $port, $errno, $errstr, 30);
if (!$fp) {
print ("ERREUR HTTP !");
} else {
fputs ($fp, $header . $xml);
while (!feof($fp)) {
$res .= htmlEntities(fgets ($fp, 1024));
}
fclose ($fp);
print($res);
} |
Jusqu'à la tout va bien, je récupére un code xml du genre :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| HTTP/1.1 200 OK
Date: Wed, 18 Feb 2009 12:28:16 GMT
Server: ServerName/XML-RSA Server
Content-Length: 701
Content-Type: text/xml
<?xml version='1.0' encoding="UTF-8" standalone="no" ?>
<!DOCTYPE OPS_envelope SYSTEM "ops.dtd">
<OPS_envelope>
<header>
<version>0.9</version>
</header>
<body>
<data_block>
<dt_assoc>
<item key="protocol">XCP</item>
<item key="object">DOMAIN</item>
<item key="response_text">Unexpected response received from the Registry: [500] [Error 2502 from ar.nic.es]</item>
<item key="action">REPLY</item>
<item key="attributes">
<dt_assoc>
<item key="status">invalid</item>
<item key="match"></item>
</dt_assoc>
</item>
<item key="response_code">436</item>
<item key="is_success">0</item>
</dt_assoc>
</data_block>
</body>
</OPS_envelope> |
Hors je souhaite parser le code XML en utilisant simplexml mais je n'y arrive pas à cause de l'entête :
1 2 3 4 5
| HTTP/1.1 200 OK
Date: Wed, 18 Feb 2009 12:28:16 GMT
Server: ServerName/XML-RSA Server
Content-Length: 701
Content-Type: text/xml |
Je pense que je pourrais éventuellement mettre un compteur avec for pour ne pas enregistrer les 6 premiers lignes mais je trouve cela pas très propre, je vous demande donc quel est la méthode à utiliser pour faire ce genre de requête...
Bien sûr lorsque je lance le code suivant :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?php
$fp = fsockopen ("ssl://$host", $port, $errno, $errstr, 30);
if (!$fp) {
print ("ERREUR HTTP !");
} else {
fputs ($fp, $header . $xml);
while (!feof($fp)) {
$res .= htmlEntities(fgets ($fp, 1024));
}
fclose ($fp);
$xml = simplexml_load_string($res);
print_r($xml);
} |
J'obtiens des erreur du genre :
Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found in ...
Je vous remercie d'avance
Partager