当前位置:首页 > PHP教程 > php高级应用 > 列表

PHP使用NuSOAP调用Web服务的方法

发布:smiling 来源: PHP粉丝网  添加日期:2021-06-13 13:49:41 浏览: 评论:0 

这篇文章主要介绍了PHP使用NuSOAP调用Web服务的方法,涉及php实现web服务的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了PHP使用NuSOAP调用Web服务的方法。分享给大家供大家参考。具体如下:

Steps:

1. Download nusoap library from internet.

2. Pass parameter list in your $client->call and enjoy.

  1. <?php 
  2. require_once('./lib/nusoap.php'); 
  3. $client = new soapclientnusoap('http://www.devtrackn.com/webservice/server.php'); 
  4. $err = $client->getError(); 
  5. if ($err) { 
  6.   // Display the error 
  7.   echo '<p><b>Constructor error: ' . $err . '</b></p>'; 
  8.   // At this point, you know the call that follows will fail 
  9. } 
  10. //////////////////////////////////////////////////////// 
  11. //////////////////////////////////////////////////////// 
  12. // update_location method parameter 
  13. $param = array( 
  14.     'device_number'   => '9910948357', 
  15.     'latitude'     => '40.727757', 
  16.     'longitude'     => '-73.984366', 
  17.     'battery_status'  => '30' 
  18.   ); 
  19. // user_action method parameter 
  20. $param2 = array( 
  21.     'device_number'   => '27ab2026da5213ebd6c95e5fbe50965bdfaddf4b', 
  22.     'latitude'     => '40.727757', 
  23.     'longitude'     => '-73.984366', 
  24.     'user_action'    => 'Meeting_Test' 
  25.   ); 
  26. // sos method parameter 
  27. $param3 = array( 
  28.     'device_number'   => '9910948357', 
  29.     'latitude'     => '40.727757', 
  30.     'longitude'     => '-73.984366', 
  31.   ); 
  32. //$result = $client->call('update_location', $param); 
  33. //$result = $client->call('user_action', $param2); 
  34. //$result = $client->call('sos', $param3); 
  35. $result = $client->call('user_entity_status', array('device_number' => '27ab2026da5213ebd6c95e5fbe50965bdfaddf4b')); 
  36. //////////////////////////////////////////////////////// 
  37. //////////////////////////////////////////////////////// 
  38. // Check for a fault 
  39. if ($client->fault) { 
  40.   echo '<p><b>Fault: '; 
  41.   print_r($result); 
  42.   echo '</b></p>'; 
  43. } else { 
  44.   // Check for errors 
  45.   $err = $client->getError(); 
  46.   if ($err) { 
  47.     // Display the error 
  48.     echo '<p><b>Error: ' . $err . '</b></p>'; 
  49.   } else { 
  50.     // Display the result 
  51.     echo "<pre>"; 
  52.     print_r($result); 
  53.     echo "</pre>"; 
  54.   } 
  55. } 
  56. echo '<h2>Request</h2>'; 
  57. echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>'; 
  58. echo '<h2>Response</h2>'; 
  59. echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>'; 
  60. /* 
  61. // Display the debug messages 
  62. echo '<h2>Debug</h2>'; 
  63. echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>'; 
  64. */ 
  65. ?> 

希望本文所述对大家的php程序设计有所帮助。

Tags: NuSOAP Web

分享到: