demo_wsclient_category.php-NORUN 2.7 KB

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