How to send Parameter to Web Services and get results in XML

-4
$client = new SoapClient("http://www.webservicex.net/airport.asmx?WSDL");
            $result = $client->GetAirportInformationByCountry(array('Country' => $Country));
            $xml = $result->GetAirportInformationByCountryResult;

            $url = 'http://www.webservicex.net/airport.asmx/GetAirportInformationByCountry';
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL, $url);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
                    curl_setopt($ch, CURLOPT_POST, 1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, 'country=paramAero');
                    curl_setopt($ch, CURLOPT_HEADER, 0);
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                    $result = curl_exec($ch);
                    $err = curl_error($ch);
                curl_close($ch);

                    $result = substr($result, 114);
                $result = substr($result,0,- 30);
                $result = chop($result);
                $borra = array("Table","CityOrAirportName","<",">","/");
                $output = str_replace($borra, '',$result);
                $output = explode(PHP_EOL, $output);

            $xml = simplexml_load_string($xml);


            $i=0;
                $aero = array();
                foreach ($output as $value) {
                    if(strlen($value)>3){
                        $aero[++$i] = $value;
                    }
                }
                echo '<select id="campoAeropuerto" name="campoAeropuerto">';

                foreach($aero as $key => $value){
                    echo '<option value="'.$key.'">'.$value.'</option>';
                }
                echo '</select>';
    
asked by Kevin Pérez 23.03.2017 в 21:12
source

1 answer

0

It depends on the API, I send you an example if it helps you:

<?php 
$id = $_GET['id'];
$site_id_search = $id;
$disccount = $_GET['disccount'];

$client = new SoapClient('https://test.com/store40/SWS.asmx?WSDL',
  array('features'=>SOAP_SINGLE_ELEMENT_ARRAYS, 
     'soap_version' => SOAP_1_1,
     'encoding'=>'UTF-8',
     'trace' => 1 ));

  $params = array(
   'LookupUser_Request' => array(
      'Username'=>'superusuario',
      'Password'=>'passweosds',
      'Channel'=> '1'  
      ),
 'Request' => array(
    'SiteID' => $site_id_search,
    'Status' => array(
      'StatusItem' => 'Available'
      ),
    ),
 ); 

$method = $client->GetSiteUnitDataV2($params);
$pre_result = json_encode($method, true);
$result = json_decode($pre_result, true);

foreach ($result as $GetSiteUnitDataV2Result){ 
  foreach ($GetSiteUnitDataV2Result as $Units){ 
    foreach ($Units as $item){ 

      $items = count($item);

      for($i=0; $i<$items; $i++){
          $unit['unit'][$i]= array(
            'unit_id' => $item[$i]['UnitId'], 
            'site_id' => $item[$i]['SiteId'],
            'rent_rate' => number_format($item[$i]['StreetRate'], 2),
            'web_price' => number_format(($item[$i]['StreetRate'] - ($item[$i]['StreetRate'] * $disccount / 100)), 2),
            'web_price_ok' => number_format(($item[$i]['StreetRate'] - ($item[$i]['StreetRate'] * $disccount / 100)), 2,".",""),
            'width' => number_format($item[$i]['Width'],2),
            'depth' => number_format($item[$i]['Depth'],2),
            'area' => number_format(($item[$i]['Width']*$item[$i]['Depth']),2),
            'level' => $item[$i]['Attribute1Value']
            //'level' => $item[$i]['Attribute1'].($item[$i]['Attribute1']=='1'?'er Nivel':'do Nivel')
          );
       }

      echo $json = json_encode($unit, true);
    }
  }
}




?>
    
answered by 23.03.2017 в 21:31