sample to request soap by curl

<?php

$soap_request = <<<END
<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”>
   <soapenv:Header/>
   <soapenv:Body>
      <OpenSession  xmlns=”http://xml.inetpsa.com/Services/SFG/Service_Dealer”>
         <RequestLoad xmlns=”http://xml.inetpsa.com/Services/SFG/Service_dealer”>
            <IdSession></IdSession>
            <Site>
               <Login>CFG</Login>
               <Password>recette</Password>
            </Site>
            <Context>
               <Country>FR</Country>
               <Language>fr-fr</Language>
               <FinancingMake>AP</FinancingMake>
               <Currency>EUR</Currency>
               <FlowDate>2011-07-08T15:42:38.0Z</FlowDate>
            </Context>
         </RequestLoad>
      </OpenSession>
   </soapenv:Body>
</soapenv:Envelope>
END;

$header = array(
    “Content-Type: text/xml;charset=UTF-8”,
    “SOAPAction: \”http://xml.inetpsa.com/Services/SFG/Service_Dealer#OpenSession\””
  );

  $soap_do = curl_init();
  curl_setopt($soap_do, CURLOPT_URL, “https://sfg-bpf.servicesgp.mpsa.com/fr/services/ServicePSAGF_Dealer.asmx”);
 
  curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true);
 
  curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
  curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
 
  curl_setopt($soap_do, CURLOPT_POST,           true );
  curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
  curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);

  $xml = curl_exec($soap_do);
 
  if($xml === false) {
    $err = ‘Curl error: ‘ . curl_error($soap_do);
    curl_close($soap_do);
    print $err;
  }
  else {
    curl_close($soap_do);
   
    $xmlObject = simplexml_load_string($xml, null, null, “http://schemas.xmlsoap.org/soap/envelope/”);
   
      var_dump($xml);
      var_dump($xmlObject);
  }

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s