【问题标题】:How to retrieve xml from my webservice in php如何在 php 中从我的 web 服务中检索 xml
【发布时间】:2012-07-31 14:15:31
【问题描述】:

我在这里使用 php 中的网络服务:

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

您可以使用idModule = dafda774-317d-4b5f-bb8b-33e5977dc13c 测试例如getListing,然后点击invoke

我正在尝试在 php.ini 中检索此结果 (XML)。但我不知道该怎么做。

如果我像这样使用 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

如何获取 XML ?谢谢你!

【问题讨论】:

  • 查看API文档看是否有xml输出模式?

标签: php xml web-services soap


【解决方案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);
?>

【讨论】:

  • 我有这个错误:警告:fsockopen()[function.fsockopen]:无法连接到cdt33.tourinsoft.com/soft/RechercheDynamique/Syndication/…(无法找到套接字传输“http” - 你忘记启用它了吗?已配置 PHP?),并且 fsockopen 已启用。
  • @ClémentAndraud ,我没有任何东西可以测试它,就像我说的那样已经有几年了,但我想我解决了你遇到的错误。
  • 不,结果只是一个空的html页面。
  • @ClémentAndraud 尝试从这里运行它: 其中 test.php 是文件名。并检查结果或日志中的错误。
  • @ClémentAndraud 好吧,我测试了这个,只需查看生成网页的源代码,您的 xml 将存储在 $content 变量中。
【解决方案2】:

假设您使用的是标准 PHP SoapClient,请尝试使用

$client->__getLastRequestHeaders()

(http://www.php.net/manual/en/soapclient.getlastresponse.php) 根据maual,您还应该在SoapClient上将trace选项设置为true:

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

问候,雅库布·德尔达

【讨论】:

    【解决方案3】:

    ABRSoapClient 类扩展了 SoapClient {

    $result = "";
    
    function __doRequest($request, $location, $action, $version) 
    {
    
        $result =  parent::__doRequest($request, $location, $action, $version); 
        return $result;
    
    }
    

    }

    不是创建 SoapClient 的对象,而是创建 ABRSoapClient 的对象,这里 $result 是您来自 Web-Service 的 XML 字符串。

    您可以使用 $client->result 访问该变量;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 2016-08-21
      • 2020-12-11
      • 1970-01-01
      相关资源
      最近更新 更多