用PHP调用WEBSERVICE

<?php
require_once(‘nusoap.php’);//调用一个开源的类 下载download
$client = new soapclient(‘http://www.webservicex.net/globalweather.asmx?WSDL’, true);
$err = $client->getError();
if ($err) {
 echo ‘<h2>Constructor error</h2><pre>’ . $err . ‘</pre>’;
}
// Doc/lit parameters get wrapped
$param = array(‘CityName’ => ‘dalian’,’CountryName’ => ‘china’);
$result = $client->call(‘GetWeather’, array(‘parameters’ => $param), ”, ”, false, true,’document’,’encoded’);
// Check for a fault
if ($client->fault) {
 echo ‘<h2>Fault</h2><pre>’;
 print_r($result);
 echo ‘</pre>’;
} else {
 // Check for errors
 $err = $client->getError();
 if ($err) {
  // Display the error
  echo ‘<h2>Error</h2><pre>’ . $err . ‘</pre>’;
 } else {
  // Display the result
  echo ‘<h2>Result</h2><pre>’;
  print_r($result);
  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>’;
?>

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: