Drupal Services 3 - XML-RPC Session Autentication con Zend Framework
Questo piccolo esempio cerca di riassumere cosa deve fare un client XML-RPC per sfruttare le risorse esposte da un server XML-RPC creato con Services 3.x .
Il server in questione richiede l'autenticazione della sessione come metodo di accesso, pertanto il client dovrà effettuare un login con un utente di Drupal e poi sfruttare la sessione autenticata per utilizzare le risorse.
Il client per semplicità è stato creato utilizzando Zend Framework.
-
/*
-
* This example is based on the XML-RPC client library
-
* included in the Zend Framework
-
*/
-
require_once 'Zend/XmlRpc/Client.php';
-
require_once('Zend/Http/Client.php');
-
-
//Setup
-
$username = 'user';
-
$password = 'password';
-
-
//Create client
-
$client = new Zend_XmlRpc_Client($url);
-
$http_client = new Zend_Http_Client();
-
$http_client->setCookieJar();
-
$client->setHttpClient($http_client);
-
-
//Start execution
-
echo "Server: $url\n";
-
-
// Get Anonymous Session
-
echo "Connect: ";
-
try {
-
$result = $client->call('system.connect');
-
echo "OK\n";
-
}
-
catch (Exception $e) {
-
}
-
-
// Do Login to create an authenticate sessionid
-
echo "Login: ";
-
try {
-
echo "OK\n";
-
echo "User Details:\n---------\n";
-
echo "\n---------\n";
-
}
-
catch (Exception $e) {
-
}
-
-
//Logout
-
echo "Logout: ";
-
try {
-
$result = $client->call('user.logout');
-
echo "OK\n";
-
}
-
catch (Exception $e) {
-
}
-
echo 'End';