14.13.1. ProblemYou need to pass a username and password along with your XML-RPC request. 14.13.2. SolutionSet the user and pass options and call the xu_rpc_http_concise( ) method: <?php require 'utils.php'; // ... other request parameters set here $user = 'elvis'; $pass = 'the-king'; // make associative array out of these variables $request = compact('host', 'port', 'uri', 'method', 'args', 'user', 'pass'); // this function makes the XML-RPC request $result = xu_rpc_http_concise($request); ?> 14.13.3. DiscussionThe XML-RPC library does not support HTTP Basic Authentication out of the box. However, the utils.php file mentioned in 14.12, will create the correct HTTP header for you when you pass in user and pass elements to xu_rpc_http_concise( ). For instance: <?php require 'utils.php'; // ... other request parameters set here $user = 'elvis'; $pass = 'the-king'; // make associative array out of these variables $request = compact('host', 'port', 'uri', 'method', 'args', 'user', 'pass'); // this function makes the XML-RPC request $result = xu_rpc_http_concise($request); ?> In this code, the user is elvis and the pass is the-king. These variables are turned into an associative array, $request, along with the other necessary request data. (The other data is omitted for clarity.) When you pass this information to xu_rpc_http_concise( ), the helper function will base64-encode the data and construct the header for you. Assuming you have the correct credentials, the rest of the transaction should operate exactly the same as nonauthenticated requests. |