How to consume a web service in drupal


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $user = 'webservice'; #username (host site).
  2. $password = 'webservice'; #pass (host site).
  3. $xmlrpc_url = 'http://localhost/services.sandbox/services/xmlrpc'; #url to find the web services
  4. $session_id = xmlrpc($xmlrpc_url, 'system.connect');
  5.  
  6. $authenticated_session = xmlrpc($xmlrpc_url, 'user.login', $session_id['sessid'], $user, $password);
  7. $xmlrpc_result = xmlrpc($xmlrpc_url, 'node.get', $authenticated_session['sessid'], 1);
  8.  
  9. if ($xmlrpc_result === FALSE) {
  10. print '<pre>' . print_r(xmlrpc_error(), TRUE) . '<pre>';
  11. }
  12. else {
  13. print '<pre>' . print_r($xmlrpc_result, TRUE) . '<pre>';
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.