使用PHP curl的SOAP XML调用


SOAP XML call using PHP curl?

我有一个SOAP WSDL api,并且我有测试api访问权限。

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

我需要打电话从这个网址获取详细信息。我必须将我的用户名和密码发送到这个api调用中。所以我试着构建代码。代码如下所示。

    <?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);   
   ?>

我只收到了空的回复,请给我任何想法,不胜感激。

我首先要添加:

$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

这将允许您查看服务器的响应http代码。

通常,当我处理SOAP/REST服务时,我会确保Fiddler在后台运行,这会使调试变得更容易。

您可以在这里找到如何使用带有cURL的Fiddler:配置PHP cURL