xiaowei8782088 发表于 2015-8-28 14:03:08

采用php的SoapClient访问web服务

  php的SoapClient是专门用来访问web服务的类,这里以访问天气预报的web服务为例,做一个简单的实例。代码如下:
  $c = new SoapClient('http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl');
  echo "
";
  //$array = $c->__getTypes();
  $obj = $c->getWeather(array('theCityCode'=>'792'));
  $getWeatherResult = $obj->getWeatherResult;
  $info = $getWeatherResult->string;
  echo "
";
  foreach($info as $str)
  {
  echo $str;
  echo "
";
  }
  把这段代码保存在一个标准的php文件里面,访问一下即可
页: [1]
查看完整版本: 采用php的SoapClient访问web服务