demo_wsclient_other.php-NORUN 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/webservices/demo_wsclient_other.php
  19. * \brief Demo page to make a client call to Dolibarr WebServices "server_other"
  20. */
  21. // This is to make Dolibarr working with Plesk
  22. set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
  23. require_once '../master.inc.php';
  24. require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
  25. $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_other.php';
  26. //$WS_DOL_URL = 'http://localhost:8080/'; // If not a page, should end with /
  27. $WS_METHOD = 'getVersions';
  28. $ns='http://www.dolibarr.org/ns/';
  29. // Set the WebService URL
  30. dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
  31. $soapclient = new nusoap_client($WS_DOL_URL);
  32. if ($soapclient)
  33. {
  34. $soapclient->soap_defencoding='UTF-8';
  35. $soapclient->decodeUTF8(false);
  36. }
  37. // Call the WebService method and store its result in $result.
  38. $authentication=array(
  39. 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
  40. 'sourceapplication'=>'DEMO',
  41. 'login'=>'admin',
  42. 'password'=>'changeme',
  43. 'entity'=>'');
  44. // Test URL
  45. if ($WS_METHOD)
  46. {
  47. $parameters = array('authentication'=>$authentication);
  48. dol_syslog("Call method ".$WS_METHOD);
  49. $result = $soapclient->call($WS_METHOD,$parameters,$ns,'');
  50. if (! $result)
  51. {
  52. //var_dump($soapclient);
  53. //print_r($soapclient);
  54. print $soapclient->error_str;
  55. print "<br>\n\n";
  56. print $soapclient->request;
  57. print "<br>\n\n";
  58. print $soapclient->response;
  59. exit;
  60. }
  61. }
  62. /*
  63. * View
  64. */
  65. header("Content-type: text/html; charset=utf8");
  66. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
  67. echo '<html>'."\n";
  68. echo '<head>';
  69. echo '<title>WebService Test: '.$WS_METHOD.'</title>';
  70. echo '</head>'."\n";
  71. echo '<body>'."\n";
  72. echo 'NUSOAP_PATH='.NUSOAP_PATH.'<br>';
  73. echo "<h2>Request:</h2>";
  74. echo '<h4>Function</h4>';
  75. echo $WS_METHOD;
  76. echo '<h4>SOAP Message</h4>';
  77. echo '<pre>' . htmlspecialchars($soapclient->request, ENT_QUOTES) . '</pre>';
  78. echo '<hr>';
  79. echo "<h2>Response:</h2>";
  80. echo '<h4>Result</h4>';
  81. echo '<pre>';
  82. print_r($result);
  83. echo '</pre>';
  84. echo '<h4>SOAP Message</h4>';
  85. echo '<pre>' . htmlspecialchars($soapclient->response, ENT_QUOTES) . '</pre>';
  86. echo '</body>'."\n";
  87. echo '</html>'."\n";
  88. ?>