xml的Web服务

Web服务用的是SOAP(简单对象访问协议):是web服务的通信协议,用来定义返回信息的xml格式的规范

技术
后缀
Asp.asp
php.php
.net(跨语言).aspx
java.jsp

Wsdl:web服务描述语言,包括一系列web服务的定义。

注意:PHP默认不支持soap协议的,要在php.ini中开启soap协议


重启服务器


php利用xml调用国际航班

<?php
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
$client = new SoapClient('http://ws.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl');
$city = $client->getDomesticCity()->getDomesticCityResult->any;
$simple = new SimpleXMLElement($city);

$addr_array = $simple->Airline1->Address;
?>
<form id="form1" name="form1" method="post" action="">
	出发城市:
	<select name="startCity" id="startCity">
		<?php
		foreach($addr_array as $row) :
		?>
			<option><?php echo $row->cnCityName; ?></option>
		<?php
		endforeach;
		?>
	</select>
	到达城市:
	<select name="lastCity" id="lastCity">
		<?php
		foreach($addr_array as $row) :
		?>
			<option><?php echo $row->cnCityName; ?></option>
		<?php
		endforeach;
		?>
	</select>
	时间:<input type="text" name="theDate" value="<?php echo date('Y-m-d'); ?>" />
	<input type="submit" name="button" id="button" value="提交" />
</form>
<?php
if(!empty($_POST)){
	$startCity = $_POST['startCity'];
	$lastCity = $_POST['lastCity'];
	$theDate = $_POST['theDate'];
	$param = array(
		'startCity'=>$startCity,
		'lastCity'=>$lastCity,
		'theDate'=>$theDate,
		'userId'=>''
	);
	$airline_str = $client->getDomesticAirlinesTime($param)->getDomesticAirlinesTimeResult->any;
	$simple = new SimpleXMLElement($airline_str);
	echo '<pre>';
	$airline_array = $simple->Airlines->AirlinesTime;
?>
<table width="780" border="1" bordercolor="#000000" align="center">
<tr>
	<th>航空公司</th>
	<th>航班</th>
	<th>出发机场</th>
	<th>到达机场</th>
	<th>起飞时间</th>
	<th>到达时间</th>
	<th>机型</th>
	<th>停靠站</th>
	<th>分型日期</th>
</tr>
<?php
foreach($airline_array as $airline) :	
?>
<tr>
	<th><?php echo $airline->Company; ?></th>
	<th><?php echo $airline->AirlineCode; ?></th>
	<th><?php echo $airline->StartDrome; ?></th>
	<th><?php echo $airline->ArriveDrome; ?></th>
	<th><?php echo $airline->StartTime; ?></th>
	<th><?php echo $airline->ArriveTime; ?></th>
	<th><?php echo $airline->Mode; ?></th>
	<th><?php echo $airline->AirlineStop; ?></th>
	<th><?php echo $airline->Week; ?></th>
</tr>
<?php
endforeach;
?>
</table>
<?php
}
?>

执行效果图:




php利用xml调用本地ip访问

<?php
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
$client = new SoapClient('http://ws.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl');
$Ip = $client->getGeoIPContext()->getGeoIPContextResult->string;
?>

<table width="780" border="1" bordercolor="#000000" align="center">
<tr>
	<th>网址</th>
</tr>
<?php
foreach($Ip as $ip) :	
?>
<tr>
	<th><?php echo $ip; ?></th>
</tr>
<?php
endforeach;
?>
</table>
<?php

执行效果图:


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值