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;
?>
如果您有任何肥皂例子。請與我分享,但我更喜歡捲曲方法。
謝謝!
能否請您解釋一下?或任何例子? –
http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528,請檢查該鏈接是否爲SOAPAction標頭。基本上這個值是用uri格式來表示消息的意圖,除非HTTP請求URL已經指明它,那麼SOAPAction將是空的(「」) – denil
現在我已經添加了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:您的操作網址 –