[eluser]veledrom[/eluser]
Hi,
I am not sure if there is something wrong here or not since I receive what I want but why do I also get the error message at end of server response?
Error:
The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.
Thanks in advance.
Client:
Code:
class Client extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->library('xmlrpc');
}
public function index()
{
$data['title'] = 'xmlrpc';
$data['heading'] = 'Welcome to xmlrpc client';
$this->load->view('client_view.php', $data);
}
public function request()
{
$this->xmlrpc->set_debug(TRUE);
$server_url = site_url('server');
$this->xmlrpc->server($server_url, 80);
$this->xmlrpc->method('login');
$request = array(
array(
array('request' => 'login'),
'struct'),
array(
array('username' => 'meme',
'password' => '1234'),
'struct')
);
$this->xmlrpc->request($request);
if(! $this->xmlrpc->send_request())
{
echo $this->xmlrpc->display_error();
}
else
{
echo '<pre>';
print_r($this->xmlrpc->display_response());
echo '</pre>';
}
}
}
SERVER:
Code:
class Server extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('xmlrpc');
$this->load->library('xmlrpcs');
}
function index()
{
$config['functions']['login'] = array('function' => 'server.login');
$config['functions']['add'] = array('function' => 'server.add');
$config['functions']['search'] = array('function' => 'server.search');
$config['functions']['list'] = array('function' => 'server.list');
$this->xmlrpcs->initialize($config);
$this->xmlrpcs->serve();
}
function login($request)
{
$username = 'meme';
$password = '1234';
$parameters = $request->output_parameters();
//echo '<pre>'; print_r($parameters); echo '</pre>'; exit;
if($parameters['1']['username'] == $username && $parameters['1']['password'] == $password)
{
$response = 'Successful';
}
else
{
$response = 'Fail';
}
$response = array(
array('client requests' => $parameters['0'],
'server responds' => $response),
'struct');
return $this->xmlrpc->send_response($response);
}
}
RESPONSE:
Code:
---DATA---
HTTP/1.1 200 OK
Date: Mon, 16 May 2011 14:15:52 GMT
Server: Apache/2.2.11 (Win32) PHP/5.3.0
X-Powered-By: PHP/5.3.0
Content-Length: 329
Connection: close
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>client requests</name>
<value>
<string>login</string>
</value>
</member>
<member>
<name>server responds</name>
<value>
<string>Successful</string>
</value>
</member>
</struct></value>
</param>
</params>
</methodResponse>
---END DATA---
The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.