使用curl发送XML数据

时间:2015-06-11 08:40:34

标签: php xml soap

我正在尝试调用webservice uisng curl。我在运行此脚本时收到“连接超时”错误。请帮我解决这个问题。

客户端:

<?php 

    #parameters
    $strParams          = '';
    $strAPIname         = 'CordecAPI';
    $url                = 'http://86.17.13.109:81/Webbooker';

    $xml = '<?xml version="1.0" encoding="UTF-8"?>
            <SOAPENV:Envelope 
            xmlns:SOAPENV="http://www.w3.org/2003/05/soap-envelope" 
            xmlns:SOAPENC="http://www.w3.org/2003/05/soap-encoding" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
              <SOAPENV:Body>
                <JobRequest xmlns="http://81.105.223.86:80/cni">
                  <SourceSystem>KVCARS</SourceSystem>
                  <SourcePassword>Ketchup96</SourcePassword>
                  <SourceJobID>*KV001*</SourceJobID>
                  <SourceAccount>CORDIC</SourceAccount>
                  <TargetSystem>TARGET1</TargetSystem>
                  <Lifetime>60</Lifetime>
                  <DriverNotes>Please wait at reception.</DriverNotes>
                  <OperatorNotes>Test job for CNI.</OperatorNotes>
                  <BookerName>Jane</BookerName>
                  <BookerPhone>01954233255</BookerPhone>
                  <BookerEmail>jane.test@cordic.com</BookerEmail>
                  <StopList>
                    <Stop>
                      <Order>1</Order>
                      <Passenger>Fara Arani</Passenger>
                      <Address>Cordic Ltd, 1 Rowles Way, Swavesey, Cambridge</Address>
                      <Postcode>CB24 4UG</Postcode>
                      <ContactPhone>01954233255</ContactPhone>
                      <ContactOnArrive>Ring</ContactOnArrive>
                    </Stop>
                    <Stop>
                      <Order>2</Order>
                      <Address>Heathrow Airport, Terminal 4</Address>
                      <Postcode>TW6 3GA</Postcode>
                    </Stop>
                  </StopList>
                  <AttributeList>
                    <Attribute>Executive</Attribute>
                    <Attribute>Professional</Attribute>
                  </AttributeList>
                </JobRequest>
              </SOAPENV:Body>
            </SOAPENV:Envelope>';

            $soap_do = curl_init(); 
            curl_setopt($soap_do, CURLOPT_URL,            $url ); 
            curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');         
            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,    $xml); 
           curl_setopt($soap_do, CURLOPT_HTTPHEADER,     array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($xml) )); 
          //curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);

          $result = curl_exec($soap_do);
          $err = curl_error($soap_do);
          $inf = curl_getinfo($soap_do);            
          if(!$result)
             {
                echo "CURL FAIL: $url TIMEOUT=10, CURL_ERRNO=$err";
                echo PHP_EOL . '<pre>' . PHP_EOL;
                var_dump($inf);
                echo PHP_EOL . '</pre>' . PHP_EOL;
             }
          echo $result;
          echo $err;
?>

如果你有任何肥皂的例子。请与我分享,但我对卷曲方法更加满意。

谢谢!

2 个答案:

答案 0 :(得分:0)

您必须使用SOAPAction设置标头:&#34;&#34;

//call fadeDivs on mouse over 
$('.yourImages').hover(function(){
  setInterval(fadeDivs(this),100);  
});

//This will create unique fadeOut for all images which have mouse over action
//And separate index loadind
function fadeDivs(image) {   
   $(image).fadeOut(100, function(){
       var index = $(this).data('index');
       index  = index  < images.length ? index : 0;
       $(this).attr('src', images[index]).fadeIn(100);
       $(this).attr('data-index',index)
   });
}

答案 1 :(得分:0)

嗨,解决方案已解决,

//curl_setopt($soap_do, CURLOPT_USERPWD, $user . ":" . $password);

我只是输入了用户名和密码信息,现在正在使用

Denil:

您的意见也很有帮助,非常感谢您的帮助。并感谢stackoverflow团队为此门户网站。

最诚挚的问候!

Ali Raza

+92 336 5141224