nusoap获取天气预报结果----Nusoap学习笔记(二)

有了前面的知识,我们来调用一个webservices测试。这个是获取天气预报的,相关参数如下

 

.url http://www.webservicex.net/globalweather.asmx

.wsdl http://www.webservicex.net/globalweather.asmx?wsdl

.GetCitiesByCountry
Get all major cities by country name(full / part).

.GetWeather
Get weather report for all major cities around the world.

 

客户端代码如下

 

<?php
require_once('lib/nusoap.php');
$client = new soapclient('http://www.webservicex.net/globalweather.asmx?WSDL',true);
$err = $client->getError();
if ($err) {
   echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$param = array('CityName' => 'shanghai','CountryName' => 'china');
$result = $client->call('GetWeather', array('parameters' => $param), '', '', false, true,'document','encoded');
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
   $err = $client->getError();
   if ($err) {
       echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
  echo '<h2>Result</h2><pre>';
   echo $result['GetWeatherResult'];
   echo '</pre>';
}
}
#echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
#echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?> 

 

注释掉了请求和调试信息。

 

得到的结果

 

Result


Shanghai / Hongqiao, China (ZSSS) 31-10N 121-26E 3M
Dec 30, 2009 - 09:00 AM EST / 2009.12.30 1400 UTC
from the NNE (020 degrees) at 9 MPH (8 KT):0
3 mile(s):0
39 F (4 C)
28 F (-2 C)
64%
30.27 in. Hg (1025 hPa)
Success

 

你可能感兴趣的:(C++,c,PHP,.net,C#)