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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
| <?php
$url='http://wsdnarec.haras-nationaux.fr/dnaservices/DiffusionServices';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_USERNAME=>'labeo',
CURLOPT_PASSWORD=>'',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 30,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webServices.server.ifce.fr/">
<soapenv:Header/>
<soapenv:Body>
<web:getInformationPreleveur>
<!--Optional:-->
<infoPreleveurIn>
<!--Optional:-->
<contextHn>
<!--Optional:-->
<isoLangage>EN</isoLangage>
<!--Optional:-->
<utilisateurID>LABEO</utilisateurID>
<!--Optional:-->
<applicationID>WSDNA</applicationID>
</contextHn>
<!--Optional:-->
<identID>526797</identID>
<!--Optional:-->
<identKey>T</identKey>
</infoPreleveurIn>
</web:getInformationPreleveur>
</soapenv:Body>
</soapenv:Envelope>',
CURLOPT_HTTPHEADER => array(
'Content-Type:application/soap+xml'
// 'Content-type: text/xml'
),
));
$response = curl_exec($curl);
$err=curl_error($curl);
curl_close($curl);
if ($err) {
return "cURL Error #:" . $err;
} else {
echo "url : ok";
}
echo '<br><br><br>';
echo "<pre>", htmlspecialchars($response), "</pre>";
// var_dump($response);// affiche string (676) + la chaine de caractère
// echo $response; // affiche la chaine de caractère
echo '<br><br><br>';
// $xml = simplexml_load_file( htmlspecialchars($response)); //htmlspecialchars permets de transformer en XML
$res= htmlspecialchars($response);
echo"reponse res: $res" ;
// $homepage = file_get_contents($response);
// echo"reponse homepage : $homepage";
//tu peux accéder aux éléments comme ça: (un élément est défini par <qqch>element</qqch>
// foreach( $res as $element )
// {
// print_r( $element );
// }
// echo '<br><br><br>';
// $xml =simplexml_load_file($res);
// echo $xml;
//--------------------------------------------encodage------------------------------------//
echo '<br><br><br>';
// var_dump(json_decode($response)) ; // reponse :null
echo'<br><br><br>';
// problème, il affiche également le status 200 même si erreur dans l'identKey
// var_dump(http_response_code());//affichage du code erreur
echo'<br><br><br>';
// $xml = simplexml_load_file($response);
// $appel=$xml;
// echo $appel;
// echo($xml);
// var_dump($response);
echo '<br><br><br>';
//-------------------------------------------------coupage de chaine--------------------------------//
// $xml="Warning: simplexml_load_file(): I/O warning : failed to load external entity \"<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><ns2:getInformationPreleveurResponse xmlns:ns2=\"http://webServices.server.ifce.fr/\"><informationPreleveur><adresse1>4 PLACE DE L'EGLISE</adresse1><civilite>MME</civilite><codePostal>62128</codePostal><commune>CROISILLES</commune><dateDebutFonction>2013-11-14</dateDebutFonction><mail>72880@ifce.fr</mail><nom>GENTY</nom><nuIdentificateur>526797</nuIdentificateur><nuperso>72880</nuperso><prenom>ANNE</prenom><telFixe>+33 (0)555555555</telFixe><telPortable>+33 (0)606060606</telPortable></informationPreleveur></ns2:getInformationPreleveurResponse></env:Body></env:Envelope>\"in C:\MAMP\htdocs\api\index.php on line 64";
$xml=htmlspecialchars($response);
echo $xml;
$Search = "telPortable";
// echo $Search;
// echo $response;
// echo $curl;
echo '<br><br><br>';
$IndexDebut = strpos($xml,$Search);
echo $IndexDebut;
echo '<br><br><br>';
$Longueur = strlen($xml) - strpos($xml,$Search );
echo $Longueur;
// echo ("</".$Search);
echo '<br><br><br>';
//deconne à partir de là
// $Resultat = substr($xml,$IndexDebut,$Longueur);
// echo $Resultat;
// $Resultats = substr($Resultat,0,strpos($Resultat,"<"));
// echo $Resultats;
//-------------------------------------------------------------------------------------------------------//
// $result = simplexml_load_file ( $response );
// $solution= $result->informationpreleveur[0]-> adresse1;
// echo $solution;
// $sxml = simplexml_load_file($response );
// echo $sxml->adresse1;
// $response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
// $xml = new SimpleXMLElement($response);
// $body = $xml->xpath('//SBody')[0];
// $array = json_decode(json_encode((array)$body), TRUE);
// print_r($array);
// ?> |
Partager