2012-07-31 31 views
0

我使用web服務的PHP這裏檢索XML:如何從我的web服務在PHP

http://cdt33.tourinsoft.com/soft/RechercheDynamique/Syndication/controle/syndication2.asmx

您可以idModule = dafda774-317d-4b5f-bb8b-33e5977dc13c測試例如getListing,點擊invoke

我試圖檢索這個結果(XML)在PHP中。但我不知道如何做到這一點。

如果我使用getListing,如:

$client = new SoapClient("http://cdt33.tourinsoft.com/soft/RechercheDynamique/Syndication/controle/syndication2.asmx?wsdl"); 

echo "GET LISTING"; 
$getListing = $client->getListing(
    array (
     'idModule' => "dafda774-317d-4b5f-bb8b-33e5977dc13c")); 
echo("<pre>"); 
print_r($getListing); 
echo("</pre>"); 

結果是類似的東西:

stdClass Object 
(
    [getListingResult] => stdClass Object 
     (
      [schema] => 
      [any] => 
HOTAQU03301V3EZB2005-06-29T00:00:00.0000000+02:002012-06-28T14:43:44.0000000+02:0074HOTHôtellerie1e9eb500-e0c9-4a53-b6a5-0b36faa63ed4true 2 étoiles Français www.hotel-lenovel.com +33 5 57 52 26 47 7 oui En centre ville$ Au bord de la mer Ascenseur$ Salon 22 -1.164866 Au coeur d'Arcachon, à deux pas de la gare, du théâtre de l'Olympia et de l'Office du Tourisme, le Novel bénéficie d'une situation privilégiée. Les chambres sont chaleureuses et douillettes pour un séjour....... ETC 

我怎樣才能retieve XML?謝謝 !

+0

檢查API文檔以查看它是否具有xml輸出模式? – 2012-07-31 14:26:28

+0

沒有DOC ^^ – 2012-07-31 14:31:09

回答

1

這裏有一些嘗試,運行它並檢查頁面的源代碼,它應該包含xml文件。 SOAP只是做一個帖子的一種奇特的方式。

<?php 
function smartpost($type,$host,$port='80',$path='/',$data='') { 
    $d=""; 
    $str=""; 
    $_err = 'lib sockets::'.__FUNCTION__.'(): '; 
    switch($type) { case 'http': $type = ''; case 'ssl': continue; default: die($_err.'bad $type'); } if(!ctype_digit($port)) die($_err.'bad port'); 
    if(!empty($data)) foreach($data AS $k => $v) $str .= urlencode($k).'='.urlencode($v).'&'; $str = substr($str,0,-1); 


    $fp = fsockopen($host,$port,$errno,$errstr,$timeout=30); 
    if(!$fp) die($_err.$errstr.$errno); else { 
     fputs($fp, "POST $path HTTP/1.1\r\n"); 
     fputs($fp, "Host: $host\r\n"); 
     fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
     fputs($fp, "Content-length: ".strlen($str)."\r\n"); 
     fputs($fp, "Connection: close\r\n\r\n"); 
     fputs($fp, $str."\r\n\r\n"); 

     while(!feof($fp)) $d .= fgets($fp,4096); 
     fclose($fp); 
     $result = explode("\r\n\r\n", $d, 2); 

     $header = isset($result[0]) ? $result[0] : ''; 
     $content = isset($result[1]) ? $result[1] : ''; 

    } return array($header, $content); 
} 

list($header, $content) = smartpost('http','cdt33.tourinsoft.com','80','/soft/RechercheDynamique/Syndication/controle/syndication2.asmx/getListingByIDs',array('idModule'=>'dafda774-317d-4b5f-bb8b-33e5977dc13c','ObjetTourCode' => '','IDs' => '')); 
print($content); 
?> 
+0

我有這個錯誤:警告:fsockopen()[function.fsockopen]:無法連接到http://cdt33.tourinsoft.com/soft/RechercheDynamique/Syndication/controle/syndication2。 asmx/getListingByIDs:80(無法找到套接字傳輸「http」 - 您忘記在配置PHP時啓用套接字?),並啓用fsockopen。 – 2012-07-31 15:02:12

+0

@ClémentAndraud,我沒有任何東西可以測試它,就像我說過已經過去了幾年,但是我認爲我解決了你遇到的錯誤。 – gmlime 2012-07-31 15:19:22

+0

不,結果是正確的空html頁面。 – 2012-07-31 15:20:04

0

假設你使用標準的PHP SoapClient的,請嘗試使用

$client->__getLastRequestHeaders() 

(http://www.php.net/manual/en/soapclient.getlastresponse.php) 根據maual,你也應該跟蹤選項設置爲true SoapClient的:

$client = new SoapClient("http://cdt33.tourinsoft.com/soft/RechercheDynamique/Syndication/controle/syndication2.asmx?wsdl", array('trace' => true)); 

的問候,的Jakub Derda

0

類ABRSoapClient擴展SoapClient的 {

$result = ""; 

function __doRequest($request, $location, $action, $version) 
{ 

    $result = parent::__doRequest($request, $location, $action, $version); 
    return $result; 

} 

}

而不是創造的SoapClient的對象,創建ABRSoapClient的對象,這裏$結果是網絡服務的XML字符串。

您可以使用$ client-> result來訪問該變量;