【问题标题】:Call with Post Method使用 Post 方法调用
【发布时间】:2016-01-08 16:48:57
【问题描述】:

从我通过 SOAP 调用 var_dump 得到结果如下:

WSDL 映射

stdClass 对象 ( [站点] => 数组 ( [0] => 标准类对象 ( [id] => 102728 [站点 ID] => 0 )

我想实现调用Sites数组来显示数据:

Post 方法调用 SOAP 数据

<?php 


$opts = array(
            'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
        );`enter code here`

// SOAP 1.2 client
$params = array (
    'encoding' => 'UTF-8', 
    'verifypeer' => false, 
    'verifyhost' => false, 
    'soap_version' => SOAP_1_2, 
    'trace' => 1, 'exceptions' => 1, 
    "connection_timeout" => 180, 
    'stream_context' => stream_context_create($opts) );

//disable wsdl cache 
ini_set("soap.wsdl_cache_enabled", "0"); 


$client = new SoapClient("http://www.example.com?WSDL",$params);

$result1=$client->getSiteInfo();

$zone = $result1->Sites;
if(isset($_POST['rayat'])){
    echo $zone;
}
 else {


?>

<form action="index.php" method="post">

<input id="rayat" name="rayat" size="10" type="text" value=""  />
<input id="submit" name="submit" type="submit" value="submit" />

</form>

    <?php 

    //$param = array('isbn'=>'0385503954');
    // define path to server application
    $opts = array(
                'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
            );

    // SOAP 1.2 client
    $params = array (
        'encoding' => 'UTF-8', 
        'verifypeer' => false, 
        'verifyhost' => false, 
        'soap_version' => SOAP_1_2, 
        'trace' => 1, 'exceptions' => 1, 
        "connection_timeout" => 180, 
        'stream_context' => stream_context_create($opts) );

    //disable wsdl cache 
    ini_set("soap.wsdl_cache_enabled", "0"); 

    $server = '';

     
    $client = new SoapClient("http://www.example.com?WSDL",$params);

    $result1=$client->getSiteInfo();
      
    $zone = $result1->Sites;
    if(isset($_POST['rayat'])){
        echo $zone;
    }
     else {
        

    ?>


    <form action="champ.php" method="post">

    <input id="rayat" name="rayat" size="10" type="text" value=""  />
    <input id="submit" name="submit" type="submit" value="submit" />

    </form>

    <?php
     }
     ?>
     
<?php } ?> Above code give me result is 'Array'

【问题讨论】:

    标签: php web-services soap wsdl


    【解决方案1】:

    试图获得搜索价值,它没有价值!请coorect我!

    WSDL

    stdClass 对象 ( [opsTrackerSites] => 数组 ( [0] => 标准类对象 ( [managerName] => DECOMM-MGR,GC [技术名称] => dectech )

    <?php
        $opts = array(
                        'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
                    );
    
    
            $params = array (
                'encoding' => 'UTF-8', 
                'verifypeer' => false, 
                'verifyhost' => false, 
                'soap_version' => SOAP_1_2, 
                'trace' => 1, 'exceptions' => 1, 
                "connection_timeout" => 180, 
                'stream_context' => stream_context_create($opts) );
    
            //disable wsdl cache 
            ini_set("soap.wsdl_cache_enabled", "0"); 
    
    
    
    
            $client = new SoapClient("http://example.com?WSDL",$params);
    
            $result = $client->getSiteInfo();
            $zone = $result->Sites;
            $output = '';
            if(isset($_POST['search'])){
                $searchq = $_POST['search'];
                $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
                $zone = $result->Sites;
    
                if($zone == ''){
                    $output = 'There was no search results!';
                }
                else{
                     $output .= '<div>' .$zone->techName.''.$zone->managerName.'<div>';
                     echo $output;
            }}
    ?>
     <form action="champ.search.php" method="post">
                <input type="text" name="search" placeholder="Search for Contacts..."> 
                 <input id="submit" name="submit" type="submit" value="submit" />
            </form>
    

    【讨论】:

      【解决方案2】:

      SOAP 结果是一个对象数组,正如您的 var_dump() 告诉您的那样。如果您说您的 SOAP 调用将始终只返回一个结果,您可以通过以下方式作弊:

          $zone = $result1->Sites;
          if(isset($_POST['rayat'])){
              echo 'ID: ' . $zone[0]->id . '<br>SiteID: ' . $zone[0]->siteid;
          } else {
          ...
      

      【讨论】:

        【解决方案3】:

        $zone 变量是一个数组,您不能回显一个数组,因此您要么必须遍历数组并回显每个单独的值,要么直接访问这些值,如另一个答案所示。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-08-01
          • 2012-12-02
          • 1970-01-01
          • 2017-02-17
          • 1970-01-01
          • 2016-11-24
          • 2012-08-07
          • 1970-01-01
          相关资源
          最近更新 更多