使用PHP curl调用SOAP XML?

使用PHP curl调用SOAP XML?,php,web-services,curl,soap,wsdl,Php,Web Services,Curl,Soap,Wsdl,我有一个SOAPWSDLAPI和一个测试api访问 我的SOAP Url: 我需要打电话从这个url获取详细信息。我必须将我的用户名和密码发送到此api调用中。所以我试着构建代码。代码如下所示 <?php $soapUrl='https://development.avinode.com:443/avinode/AvinodeIntegrationWeb/ws/EmptyLegDownload.ws?wsdl'; $xml_post_string='<S:Envelope

我有一个SOAPWSDLAPI和一个测试api访问

我的SOAP Url:

我需要打电话从这个url获取详细信息。我必须将我的用户名和密码发送到此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,这使得调试更加容易


您可以在此处找到如何将Fiddler与cURL一起使用:

如果禁用了错误报告,请尝试打开它,可能是脚本有错误。尝试对wsdl url执行一个简单的curl调用(GET方法),这样我们就可以确保PHP能够正确访问您的wsdl。@谢谢您的响应,但是正常的curl对我来说工作得很好。我需要将登录头发送到我的请求中。所以只有我得到了这个没有回应的问题