fouix Posted February 9, 2022 Share Posted February 9, 2022 Je travaille avec une api pour récupérer les coordonnées et comparé l'identifiant avec mon formulaire. Sauf que vu , je n'arrive pas à récupérer mes données individuel, je suis bloqué. Je ne sais pas si c'est mon encodage qui n'est pas bon ou autre. J'ai essayé déjà tellement de chose et aucun résultat Si une âme charitable pourrais m'éclairer? <?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>'; // var_dump($response);// affiche string (676) + la chaine de caractère echo $response; // affiche la chaine de caractère echo '<br><br><br>'; // var_dump(json_decode($response)) ; // reponse :null $api=print_r(json_encode($response)) ; // affiche string = balise fermantes echo $api; // 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/ Share on other sites More sharing options...
requinix Posted February 9, 2022 Share Posted February 9, 2022 $response will be XML. What is the output of // var_dump($response);// affiche string (676) + la chaine de caractère // echo $response; // affiche la chaine de caractère echo "<pre>", htmlspecialchars($response), "</pre>"; // <soapenv:Envelope ...???... </soapenv:Envelope> Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594005 Share on other sites More sharing options...
fouix Posted February 9, 2022 Author Share Posted February 9, 2022 merci beaucoup, déjà la réponse est bien plus clair, avant je ne récupérerai que les balises fermantes dans mon navigateur malgré que dans ma console, je récupérer bien le bon résultat. Maintenant en xml, je fais comment si je veux récupérer que une donnée? car que ce sois entre crochet ou fléché, je n'obtiens aucun résultat mise a part des erreurs Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594006 Share on other sites More sharing options...
requinix Posted February 9, 2022 Share Posted February 9, 2022 This would be easier to explain if I could see what $response contains. Because it is XML, if you "echo $response" then all the <tags> in it will be invisible, but any <tag>123</tag> will show up as "123". To see the XML and the <tags>, either "htmlspecialchars($response)" like I showed before, or View Source in your browser. Here is an example of how you can read a SOAP response using SimpleXML. If you want to see the "u:month" value inside the <dimension>, 1. The first element is the Envelope. You need to be in the "soapenv" namespace to access it, so call children() with the URI noted in the xmlns attribute. You do not need ->Envelope because $xml is already the root node. 2. The second element is the Body. You need to be in the "soapenv" namespace, but you are already so you do not need to call children() again. Then ->Body. 3. The third element is the getDataResponse. That is the "tns" namespace so call children() again, then ->getDataResponse. 4. Next is the record. It is not in any namespace, which means it is in in the default namespace, but there is no default "xmlns" attribute anywhere to tell you a special URI so use just "". Then ->record. There are multiple "record"s so add [0] for the first item. 5. Next is dimensions, which is also in the default namespace, so ->dimensions. 6. Next is dimension, so ->dimension. Finally you can use ["name"] to get the attribute, but only because it is also in the default namespace. If you can show the XML response you are receiving, with the XML <tags>, then I can show you the exact PHP code to get the information you need. Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594008 Share on other sites More sharing options...
fouix Posted February 9, 2022 Author Share Posted February 9, 2022 here is my screenshot from my browser Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594016 Share on other sites More sharing options...
fouix Posted February 9, 2022 Author Share Posted February 9, 2022 I have to put a variable in my identId and then, if IdentId ok, the address, phone etc fields will be filled otherwise the form will be grayed out <!DOCTYPE html> <html lang="fr"> <head> <title>LABEO</title> <meta charset="utf-8"> <meta name="description" lang="fr" content="formulaire de kit génomiques"> <meta name="author" content="Gabrielle"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!--boostrap pour la barre de navigation--> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> <!--icônes--> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous"> <!--CSS--> <link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/style.css"> </head> <?php if(!empty($_POST)) { // echo '<pre>'; print_r($_POST); echo '</pre>'; // entête email $headers = 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-type: text/html; charset=ISO-8859-1'."\n"; $headers .= 'Reply-To: ' . $_POST['expediteur'] . "\n"; $headers .= 'From: "' . ucfirst(substr($_POST['email'], 0, strpos($_POST['email'], '@'))) . '"<'.$_POST['email'].'>' . "\n"; $headers .= 'Delivered-to: fouix.gabrielle@gmail.com' . "\n"; $message = "Nom : " . $_POST['nom'] ."<br>". "Prénom : " . $_POST['prenom'] ."<br>". "Société : " . $_POST['society'] ."<br>"."Numéro d'identification : " . $_POST['identity']."<br>"."Nombre de kits : " . $_POST['identity']."<br>"."Rue : " . $_POST['street'] ."<br>"."Code postal : " . $_POST['postal'] ."<br>"."Ville : " . $_POST['city'] ."<br>"."Email : " . $_POST['email'] ."<br>"."Tel : " . $_POST['phone'] ."<br>"."Commentaire : " . $_POST['message']."<br>"."RGPD : " . $_POST['rgpd'] ; mail("fouix.gabrielle@gmail.com", $_POST['sujet'], $message, $headers); } ?> <body> <div class="contact container"> <div class="row justify-content-center"> <div class="col-10 text-center"> <h1>Commande de kits génomique</h1> </div> </div> <form method="post" action="" enctype="multipart/form-data"> <div class="form-row justify-content-center bg-light py-5"> <div class="form-group col-lg-4"> <label for="identity"></label> <input type="text" class="form-control" id="identity" name="identity" placeholder="Numéro d'identificateur"required/> </div> <div class="form-group col-lg-4"> <label for="identity"></label> <input type="text" class="form-control" id="identity" name="identity" placeholder="Numéro d'identificateur"required/> </div> <div class="form-group col-lg-5"> <label for="nom"></label> <input type="text" class="form-control" id="nom" name="nom" placeholder="Votre nom" required> </div> <div class="form-group col-lg-5"> <label for="prenom"></label> <input type="text" class="form-control" id="prenom" name="prenom" placeholder="Votre prénom"required> </div> <div class="form-group col-lg-10"> <label for="street"></label> <input type="text" class="form-control" id="street" name="street" placeholder="Rue" required/> </div> <div class="form-group col-lg-5"> <label for="postal"></label> <input type="text" class="form-control" id="postal" name="postal" placeholder="Code postal" required/> </div> <div class="form-group col-lg-5"> <label for="city"></label> <input type="text" class="form-control" id="city" name="city" placeholder="Ville" required/> </div> <div class="form-group col-lg-5"> <label for="email"></label> <input type="email" class="form-control" id="email" name="email" placeholder="Email" required/> </div> <div class="form-group col-lg-5"> <label for="phone"></label> <input type="text" class="form-control" id="phone" name="phone" placeholder="phone" maxlength="10" pattern="[0-9]{10}" required/> </div> <div class="form-group col-lg-4"> <label for="kit"></label> <input type="number" class="form-control" id="kit" name="kit" placeholder="Nombre de Kits"required/> </div> <div class="form-group col-lg-3"> <label for="aiguilles"></label> <input type="number" class="form-control" id="aiguilles" name="aiguilles" placeholder="Nombre de tubes et aiguilles"required/> </div> <div class="form-group col-lg-3"> <label for="adaptateur"></label> <input type="number" class="form-control" id="adaptateur" name="adaptateur" placeholder="Nombres d'adaptateur"required/> </div> <div class="form-group col-lg-5"> <label for="small-box"></label> <input type="number" class="form-control" id="small-box" name="small-box" placeholder="Petit carton + Etiquette retour"required/> </div> <div class="form-group col-lg-5"> <label for="big-box"></label> <input type="number" class="form-control" id="big-box" name="big-box" placeholder="Grand carton + Etiquette retour"required/> </div> <div class="form-group col-lg-10"> <!-- <label for="message">Commentaire</label> --> <textarea class="form-control" id="message" rows="3" name="message" placeholder="commentaires"></textarea> </div> <div class="form-group col-lg-10 "style="display:flex"> <div class="form-group col-lg-2 "> <input type="checkbox" class="form-control" id="rgpd" name="rgpd" required/> </div> <div class="form-group col-lg-8 "> <label for="rgpd"> En cochant cette case, j’accepte la Politique de confidentialité de ce site </label> </div> </div> <input type="submit" name="valider" id="valider" value="Valider" class="form-control btn btn-light text-dark"/> </div> </form> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594021 Share on other sites More sharing options...
requinix Posted February 10, 2022 Share Posted February 10, 2022 If $response is that XML then $xml = simplexml_load_string($response); $ip = ->children("http://schemas.xmlsoap.org/soap/envelope/") // <env:*> ->body // <env:body> ->children("http://webServices.server.ifce.fr/") // <ns2:*> ->getInformationPreleveurResponse // <ns2:getInformationPreleveurResponse> ->children("") // <*> ->informationPreleveur; // <informationPreleveur> echo (string)$ip->adresse1; // 4 PLACE DE L'EGLISE Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594039 Share on other sites More sharing options...
fouix Posted February 10, 2022 Author Share Posted February 10, 2022 Hello, I tried your code and the example. I don't understand your $ip. In your code, syntax error. from the beginning I have a problem with simplexml, there is no answer. In the exemple code ,warning $adresse1 // 1- <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'> $envelope = $ifce ->children("http://schemas.xmlsoap.org/soap/envelope/"); echo"$ envelope: $envelope"; //2- <env:Body> $Body=$envelope->Body; echo "$ body : $Body"; //3-<ns2:getInformationPreleveurResponse xmlns:ns2="http://webServices.server.ifce.fr/"> $ns2=$Body->children("http://webServices.server.ifce.fr/"); echo "$ ns2: $ns2"; $getInformationPreleveurResponse=$ns2->getDataResponse; echo "$ getinformationPreleveurResponse: $getInformationPreleveurResponse"; //4- <informationPreleveur> $default=$getInformationPreleveurResponse; echo "$ defaut: $default"; $informationPreleveur=$default->informationPreleveur; echo "$ informationPreleveur: $informationPreleveur"; //5- <adresse1> $adresse1 = $informationPreleveur->adresse1; echo "adresse1 : $adresse1"; I don't know how to solve this error 😞 Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594042 Share on other sites More sharing options...
requinix Posted February 11, 2022 Share Posted February 11, 2022 Couple typos in what I wrote: $ip = ->children("http://schemas.xmlsoap.org/soap/envelope/") // <env:*> There's a variable missing before the ->. What do you think it might be? Also ->body // <env:body> the element is actually "Body", not "body". Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594069 Share on other sites More sharing options...
fouix Posted February 11, 2022 Author Share Posted February 11, 2022 Thanks, but I believe this is the result of my answer that must not be in the correct format because I am getting empty simplexml. (see screenshot) However I connect well and in the code inspector, I receive the xml file well, I just have to find how to interpret it $ifce=simplexml_load_string($response); print_r($ifce); Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594073 Share on other sites More sharing options...
requinix Posted February 11, 2022 Share Posted February 11, 2022 5 hours ago, fouix said: Thanks, but I believe this is the result of my answer that must not be in the correct format because I am getting empty simplexml. (see screenshot) The output is technically correct. It isn't actually empty - it just isn't outputting all of what is in there. 5 hours ago, fouix said: However I connect well and in the code inspector, I receive the xml file well, I just have to find how to interpret it And I think you were making progress. Did you fix your code according to my previous reply? What is your code after you did that (the full thing, please, not just the piece you showed earlier) and what is it doing now? Quote Link to comment https://forums.phpfreaks.com/topic/314536-impossible-de-r%C3%A9cup%C3%A9rer-les-donn%C3%A9es-individuelles-de-lapi/#findComment-1594078 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.