简体   繁体   中英

SOAP XML call using PHP curl?

I have one SOAP WSDL api and i have a test api access.

My SOAP Url : https://development.avinode.com/avinode/AvinodeIntegrationWeb/ws/EmptyLegFlightDemand.ws?wsdl

i need to call and get the details from this url. i must send my username and password into this api call. so i tried to build the code. the code is given below.

    <?php  
$soapUrl='https://development.avinode.com:443/avinode/AvinodeIntegrationWeb/ws/EmptyLegDownload.ws?wsdl';
$xml_post_string='<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <S:Header>
        <To xmlns="http://www.w3.org/2005/08/addressing">https://development.avinode.com/avinode/AvinodeIntegrationWeb/ws/EmptyLegDownload.ws</To>
        <Action xmlns="http://www.w3.org/2005/08/addressing">http://www.avinode.com/integration/EmptyLegDownload#request</Action>
        <ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
            <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
        </ReplyTo>
        <FaultTo xmlns="http://www.w3.org/2005/08/addressing">
            <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
        </FaultTo>
        <MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:6a456287-923e-458e-9ccb-f900307f2b0f</MessageID>
        <wsse:Security S:mustUnderstand="1">
            <wsu:Timestamp xmlns:ns13="http://www.w3.org/2003/05/soap-envelope" xmlns:ns14="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" wsu:Id="_1">
                <wsu:Created>2014-10-17T15:45:42Z</wsu:Created>
                <wsu:Expires>2014-10-17T15:50:42Z</wsu:Expires>
            </wsu:Timestamp>
            <wsse:UsernameToken xmlns:ns13="http://www.w3.org/2003/05/soap-envelope" xmlns:ns14="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" wsu:Id="uuid_2da8da35-1c69-4f38-9899-ba6950c825f5">
                <wsse:Username>MY_USERNAME</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </S:Header>
    <S:Body>
        <ns3:request xmlns="http://www.avinode.com/core/CommonTypes" xmlns:ns2="http://www.avinode.com/services/EmptyLegDownload" xmlns:ns3="http://www.avinode.com/integration/EmptyLegDownload">
            <ns2:product>
                <name>osiz</name>
                <version>1.0</version>
            </ns2:product>
            <ns2:domain>http://flightcomparision.osiztechnologies.com</ns2:domain>
            <ns2:locale>en_US</ns2:locale>
            <ns2:currency>USD</ns2:currency>
            <ns2:region>AMERICA</ns2:region>
            <ns2:after>2014-11-01T00:00:00Z</ns2:after>
            <ns2:before>2014-12-01T00:00:00Z</ns2:before>
            <ns2:pax>1</ns2:pax>
            <ns2:excludeBrokers>false</ns2:excludeBrokers>
            <ns2:requireTailNumber>false</ns2:requireTailNumber>
        </ns3:request>
    </S:Body>
</S:Envelope>';




   $headers = array( 
   "Content-Type: text/xml;charset=UTF-8", 
   "Accept: gzip,deflate", 
   "Cache-Control: no-cache", 
   "Pragma: no-cache", 
   "SOAPAction: \"\"", 
   "Authorization: Basic $auth", 
   "Content-length: ".strlen($xml_post_string), 
   ); 

   // PHP cURL  for https connection with auth
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_URL, $soapUrl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
   curl_setopt($ch, CURLOPT_TIMEOUT, 500);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
   curl_setopt($ch, CURLOPT_MAXREDIRS, 12);
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   $ss = curl_getinfo($ch);
   //print_r($ss);
  // exit;
   $response = curl_exec($ch); 
   print_r($response);
   exit;
   curl_close($ch);   
   ?>

I got only Empty response only please give me any idea highly appreciated.

I would start by adding:

$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

That will allow you to see the response http code of the server.

Usually when I work on SOAP / REST services I make sure to have Fiddler running in the background, that makes debugging a lot easier.

You can find how to use Fiddler with cURL here: Configure PHP cURL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM