IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Comment puis-je voir ce que mon curl envoie [PHP 5.5]


Sujet :

Langage PHP

  1. #1
    Membre habitué
    Homme Profil pro
    Aprenti
    Inscrit en
    Mai 2015
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Aprenti

    Informations forums :
    Inscription : Mai 2015
    Messages : 199
    Points : 140
    Points
    140
    Par défaut Comment puis-je voir ce que mon curl envoie
    Bonjour,
    J'envoie des données à un web services par curl.
    Mon lien :Mon data :
    <commande>
    <commandeType>O</commandeType>
    <transId>123456</transId>
    <promotion>NEWYEAR</promotion>
    <client>
    <city>PARIS</city>
    <true>N</true>
    </client>
    </commande>
    et j'aimerais bien obtenir cela :
    https://webserviceexterne.com/ws/commande/TOTO?appId=qscvhu&pwd=1598753&xml=<commande><commandeType>O</commandeType><transId>123456</transId><promotion>NEWYEAR</promotion><client><city>PARIS</city><true>N</true></client></commande>
    alors ce que je fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $xml_data = '<commande>
    				<commandeType>O</commandeType>
    				<transId>123456</transId> 
    				<promotion>NEWYEAR</promotion>
    				<client>                                                        
    					<city>PARIS</city>                                                                   
    					<true>N</true>                                                 
    				</client>
    			</commande>';
     
    $url_ws = 'https://webserviceexterne.com/ws/commande/TOTO?appId=qscvhu&pwd=1598753&xml=';	
     
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url_ws);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // recevoir le résultat du transfert 
    	curl_setopt($curl, CURLOPT_COOKIESESSION, true); // démarrer un nouveau cookie session
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl,CURLOPT_POSTFIELDS, $xml_data);
     
     
     
     
     
    $response = curl_exec($curl);
     
     
    curl_close($curl);
    Mais je ne peux pas tester pour le moment puisque je n'ai pas toutes les informations :
    • appId : ???
    • pwd : ???

    Comment puis-je faire un test sans la connexion ?
    J'aimerais savoir si mon code est bon sans envoyer les infos à webservices ?

    J'ai essayé avec echo
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo '<p>' . curl_setopt($curl,CURLOPT_POSTFIELDS, $xml_data) . '</p>'
    je reçois qu'un : 1

    Donc il faudrait d'autres chose.

    Merci

  2. #2
    Membre habitué
    Homme Profil pro
    Aprenti
    Inscrit en
    Mai 2015
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Aprenti

    Informations forums :
    Inscription : Mai 2015
    Messages : 199
    Points : 140
    Points
    140
    Par défaut
    Est ce que quelqu'un peut m'aider pour cette histoire ?

    merci

  3. #3
    Membre habitué
    Homme Profil pro
    Aprenti
    Inscrit en
    Mai 2015
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Aprenti

    Informations forums :
    Inscription : Mai 2015
    Messages : 199
    Points : 140
    Points
    140
    Par défaut au swcours
    Bonjour,

    J'ai toutes les informations.

    Voici mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $xml_data = '<commande>
    				<commandeType>O</commandeType>
    				<transId>123456</transId> 
    				<promotion>NEWYEAR</promotion>
    				<client>                                                        
    					<city>PARIS</city>                                                                   
    					<true>N</true>                                                 
    				</client>
    			</commande>';
     
    $url_ws = 'https://webserviceexterne.com/ws/commande/TOTO?appId=qscvhu&pwd=1598753&xml=';	
     
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url_ws);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // recevoir le résultat du transfert 
    curl_setopt($curl, CURLOPT_COOKIESESSION, true); // démarrer un nouveau cookie session
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
     
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    curl_setopt($curl,CURLOPT_POSTFIELDS, "xmlRequest=" . $xml_data);
     
    $response = curl_exec($curl);
     
    if(curl_errno($curl))
    {
        echo 'Erreur Curl : ' . curl_error($curl);
    }
    else
    {
    	$info = curl_getinfo($curl);
     
    	print_r($info);
    }
     
     print_r($response);
     
    curl_close($curl);
    Et print_r($response); m'envoie le message d'erreur par le serveur de notre fournisseur :
    Unable to parse the specified order data from request body. Unable to parse xml file
    Est-ce que vous pouvez m'aider ?

    Merci

  4. #4
    Membre habitué
    Homme Profil pro
    Aprenti
    Inscrit en
    Mai 2015
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Aprenti

    Informations forums :
    Inscription : Mai 2015
    Messages : 199
    Points : 140
    Points
    140
    Par défaut ????
    Je n'ai pas encore trouvé la solution....

  5. #5
    Expert confirmé Avatar de papajoker
    Homme Profil pro
    Développeur Web
    Inscrit en
    Septembre 2013
    Messages
    2 217
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nièvre (Bourgogne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2013
    Messages : 2 217
    Points : 4 699
    Points
    4 699
    Par défaut
    Bonjour,

    le service te retourne Unable to parse xml file c'est donc clairement qu'il ne comprend pas ton xml !

    Il me semble très bizarre que tu envois 2 fois un champ nonmé xml*, une fois avec get(xml) et une autre avec post(xmlRequest). Il ne lirait pas l'entrée xml= ?

    et je ne suis pas sur de ta donnée envoyée en post "xmlRequest=" . $xml_data, normalement c'est un tableau

  6. #6
    Membre habitué
    Homme Profil pro
    Aprenti
    Inscrit en
    Mai 2015
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Aprenti

    Informations forums :
    Inscription : Mai 2015
    Messages : 199
    Points : 140
    Points
    140
    Par défaut
    Bonjour papajoker,

    Merci pour tes réflexions...

    Je suis en train de refaire mon code selon tes idées...

    En attendant, j'aimerais bien savoir où tu vois qu'il y a un get(xml) ?

    Merci

  7. #7
    Membre habitué
    Homme Profil pro
    Aprenti
    Inscrit en
    Mai 2015
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Aprenti

    Informations forums :
    Inscription : Mai 2015
    Messages : 199
    Points : 140
    Points
    140
    Par défaut
    Voilà,

    J'ai rectifié le code...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $xml_data = '<commande>
    				<commandeType>O</commandeType>
    				<transId>123456</transId> 
    				<promotion>NEWYEAR</promotion>
    				<client>                                                        
    					<city>PARIS</city>                                                                   
    					<true>N</true>                                                 
    				</client>
    			</commande>';
     
    $url_ws = 'https://webserviceexterne.com/ws/commande/TOTO?appId=qscvhu&pwd=1598753&xml=';	
     
    $headers = array(
    					'Content-Type: text/xml;charset=utf-8;xml version=1.0'
    				);	 //NEW!!!	
     
     
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url_ws);
    curl_setopt($curl, CURLOPT_POST, true);
     
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     
     
    //curl_setopt($curl,CURLOPT_POSTFIELDS, "xmlRequest=" . $xml_data);
    curl_setopt($curl,$curl,CURLOPT_POSTFIELDS, $xml_data);  //NEW!!!
     
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // recevoir le résultat du transfert 
     
     
    //curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);  //NEW!!!
     
     
    $response = curl_exec($curl);
     
    if(curl_errno($curl))
    {
        echo 'Erreur Curl : ' . curl_error($curl);
    }
    else
    {
    	$info = curl_getinfo($curl);
     
    	print_r($info);
    }
     
    print_r($response);
     
    curl_close($curl);
    Il n'y a pas d'erreur par curl_error

    Mais le webService (print_r($response)) me répond par le même message suivant :

    "Unable to parse the specified order data from request body. Unable to parse xml file"

  8. #8
    Membre habitué
    Homme Profil pro
    Aprenti
    Inscrit en
    Mai 2015
    Messages
    199
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Aprenti

    Informations forums :
    Inscription : Mai 2015
    Messages : 199
    Points : 140
    Points
    140
    Par défaut
    Salut,

    Je l'ai trouvé :

    En fait, comme papajoker a dit :

    Citation Envoyé par papajoker Voir le message
    Il me semble très bizarre que tu envois 2 fois un champ nonmé xml*, une fois avec get(xml) et une autre avec post(xmlRequest). Il ne lirait pas l'entrée xml= ?

    et je ne suis pas sur de ta donnée envoyée en post "xmlRequest=" . $xml_data, normalement c'est un tableau
    J'ai ajouté dans ma varaible $xml_data :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <?xml version="1.0" encoding="utf-8"?>
    J'ai supprimé '&xml=" dans $url_ws

    J'ai supprimé : $headers et 'CURLOPT_HTTPHEADER'

    J'ai rectifié 'CURLOPT_POSTFIELDS'

    ça marche

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $xml_data = '<?xml version="1.0" encoding="utf-8"?>
    			<commande>
    				<commandeType>O</commandeType>
    				<transId>123456</transId> 
    				<promotion>NEWYEAR</promotion>
    				<client>                                                        
    					<city>PARIS</city>                                                                   
    					<true>N</true>                                                 
    				</client>
    			</commande>';
     
    //$url_ws = 'https://webserviceexterne.com/ws/commande/TOTO?appId=qscvhu&pwd=1598753&xml=';	
    $url_ws = 'https://webserviceexterne.com/ws/commande/TOTO?appId=qscvhu&pwd=1598753';
     
    /* supp
    $headers = array(
    					'Content-Type: text/xml;charset=utf-8;xml version=1.0'
    				);	 //NEW!!!	
     */
     
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url_ws);
    curl_setopt($curl, CURLOPT_POST, true);
     
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     
     
    //curl_setopt($curl,CURLOPT_POSTFIELDS, "xmlRequest=" . $xml_data);
    //curl_setopt($curl,$curl,CURLOPT_POSTFIELDS, $xml_data);  //NEW!!!
    curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array('xml' => $xml_data)));
     
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // recevoir le résultat du transfert 
     
     
    //curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    //curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);  //NEW!!!
     
     
    $response = curl_exec($curl);
     
    if(curl_errno($curl))
    {
        echo 'Erreur Curl : ' . curl_error($curl);
    }
    else
    {
    	$info = curl_getinfo($curl);
     
    	print_r($info);
    }
     
    print_r($response);
     
    curl_close($curl);

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comment puis-je ne sélectionner que le premier <li>
    Par pierrot10 dans le forum Mise en page CSS
    Réponses: 7
    Dernier message: 09/07/2013, 16h53
  2. Réponses: 2
    Dernier message: 15/04/2011, 17h45
  3. Voir ce que mon navigateur envoie
    Par Monstros Velu dans le forum Internet
    Réponses: 3
    Dernier message: 31/05/2008, 16h54
  4. Comment puis je faire pour que'une page soir rechargees....
    Par pierrot10 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 23/12/2005, 10h46
  5. Comment être sure que mon appli prenne le focus ?
    Par AmaX dans le forum Composants VCL
    Réponses: 2
    Dernier message: 21/12/2002, 15h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo