2015-06-11 63 views
1

我想調用web服務uisng curl。運行此腳本時,我收到「連接超時」錯誤。請協助我解決這個問題。使用curl發送XML數據

客戶:

<?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>[email protected]</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; 
?> 

如果您有任何肥皂例子。請與我分享,但我更喜歡捲曲方法。

謝謝!

回答

0

嗨,方案解決,

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

我只是把用戶名和密碼信息,並且其現在的工作

Denil:

您的意見也很有幫助,非常感謝您的幫助NG。並感謝這個門戶的stackoverflow團隊。

最好的問候!

阿里·拉扎

+92 336 5141224

0

必須設定的SOAPAction頭: 「」

curl_setopt ($ch, CURLOPT_HTTPHEADER, array('SOAPAction: ""')); 
+0

能否請您解釋一下?或任何例子? –

+0

http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528,請檢查該鏈接是否爲SOAPAction標頭。基本上這個值是用uri格式來表示消息的意圖,除非HTTP請求URL已經指明它,那麼SOAPAction將是空的(「」) – denil

+0

現在我已經添加了SOAPAction,但我仍然看到這個錯誤 $ headers = array( 「Content-type:text/xml; charset = \」utf-8 \「」, 「Accept:text/xml」, 「Cache-Control:no-cache」, 「Pragma:no -cache「, 」SOAPAction:http://86.17.13.109:81/Webbooker「, 」Content-length:「.strlen($ xml), ); // SOAPAction:您的操作網址 –