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

Bibliothèques et frameworks PHP Discussion :

[Web Service] Envoi de code XML par POST


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Juillet 2010
    Messages
    82
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2010
    Messages : 82
    Points : 43
    Points
    43
    Par défaut [Web Service] Envoi de code XML par POST
    Bonjour, je tente d'envoyer un flux XML SOAP en POST à un webservice. Cela fait plusieurs heures que je lutte à trouver la solution....En vain. Voici le code que j'utilise et l'erreur retournée par le serveur.

    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
    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
    <?php
    header('POST /admin/wbsContact.asmx HTTP/1.1 Host: xxxxxxxxxxxxxxx Content-Type: text/xml; charset=utf-8 Content-Length:300000 SOAPAction: "http://tempuri.org/ContactCreateUpdate"' );
     
    error_reporting(E_ALL);
     
    // The POST URL and parameters
    $request =  'http://xxxxxxxxxxxxxxxx/admin/wbsContact.asmx?op=ContactCreateUpdate';
     
    $postargs = '<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <ContactCreateUpdate xmlns="http://tempuri.org/">
     
          <intPortail_id>347</intPortail_id>
          <ostContact>
            <strContact_idExterne>1</strContact_idExterne>
            <strContact_lastName>test</strContact_lastName>
            <strContact_firstName>test</strContact_firstName>
            <strContact_phone>test</strContact_phone>
            <strContact_mobilePhone>test</strContact_mobilePhone>
            <strContact_eMail>test</strContact_eMail>
            <strContact_idMd5>test</strContact_idMd5>
            <strContact_login>test</strContact_login>
            <strContact_password>test</strContact_password>
            <datContact_birthdate>20/11/1978</datContact_birthdate>
            <bytContact_title>1</bytContact_title>
          </ostContact>
          <ostAddress>
            <intCountry_id>73</intCountry_id>
            <strAddress_address1stLine>test</strAddress_address1stLine>
            <strAddress_address2ndLine></strAddress_address2ndLine>
            <strAddress_city>test</strAddress_city>
            <strAddress_zipCode>test</strAddress_zipCode>
            <strAddress_regionName>FRANCE</strAddress_regionName>
          </ostAddress>
          <intContact_id>0</intContact_id>
          <strLangue>FR</strLangue>
        </ContactCreateUpdate>
      </soap:Body>
    </soap:Envelope>'; 
     
    // Get the curl session object
    $session = curl_init($request);
     
    // Set the POST options.
    curl_setopt ($session, CURLOPT_POST, true);
    curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
    curl_setopt($session, CURLOPT_HEADER, true);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
     
    // Do the POST and then close the session
    $response = curl_exec($session);
    curl_close($session);
     
    // Get HTTP Status code from the response
    $status_code = array();
    preg_match('/\d\d\d/', $response, $status_code);
     
    // Check for errors 
    /*
    switch( $status_code[0] ) {
    	case 200:
    		// Success
    		break;
    	case 503:
    		die('Your call to Yahoo Web Services failed and returned an HTTP status of 503. That means: Service unavailable. An internal problem prevented us from returning data to you.');
    		break;
    	case 403:
    		die('Your call to Yahoo Web Services failed and returned an HTTP status of 403. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.');
    		break;
    	case 400:
    		// You may want to fall through here and read the specific XML error
    		die('Your call to Yahoo Web Services failed and returned an HTTP status of 400. That means:  Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.');
    		break;
    	default:
    		die('Your call to Yahoo Web Services returned an unexpected HTTP status of:' . $status_code[0]);
    }*/
     
    // Get the XML from the response, bypassing the header
    if (!($xml = strstr($response, '<?xml'))) {
    	$xml = null;
    }
    echo $response;
    
    // Output the XML
    echo htmlspecialchars($xml, ENT_QUOTES);
    //echo $postargs;
    ?>
    Et voici la réponse du serveur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    HTTP/1.1 100 Continue HTTP/1.1 415 Unsupported Media Type Date: Tue, 13 Jul 2010 15:10:35 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: application/soap+xml; charset=utf-8 Content-Length: 2
    Merci par avance à ceux qui sauront m'éclairer sur ce(s) point(s)

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 49
    Points : 64
    Points
    64
    Par défaut
    Bonjour,

    Une piste :

    HTTP/1.1 415 Unsupported Media Type
    Tu envoies du text/xml, à la mode SOAP 1.1, dans les headers de l'erreur renvoyée, le serveur a préparé un :

    Content-Type: application/soap+xml;
    ...spécifié par le SOAP 1.2

    Je commencerais par réessayer avec une request dont le Content-Type est application/soap+xml

Discussions similaires

  1. Réponses: 5
    Dernier message: 03/04/2009, 10h04
  2. [Web Service] Requête et réponse XML
    Par mme_chelaou dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 05/12/2008, 17h56
  3. [ERROR] Web Service avec attachement de fichier par MTOM
    Par caballero dans le forum Services Web
    Réponses: 3
    Dernier message: 25/03/2008, 14h31
  4. [Web Service] Construire une requête XML-RPC!
    Par lekunfry dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 14/01/2008, 15h29

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