CodeIgniter Forums

Full Version: XMLRPC Response Error. Probably very easy for some of you!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]veledrom[/eluser]
Hi,

I have an issue here and am desperate to solve it. Please give me a hand. Please have a look at the response comes from server. I cannot identify which one is wrong, either request or response, maybe both!!!

Error is : 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.

Note: I also attached the files, if you wish to run on your local. Just a little and basic one anyway.

Thanks in advance

CONTROLLER: client.php

Code:
class Client extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        
        $this->load->helper('url');
        $this->load->library('xmlrpc');
        
        $this->xmlrpc->set_debug(TRUE);
    }
    
    public function index()
    {
        $data['title'] = 'xmlrpc';
        $data['heading'] = 'Welcome to xmlrpc client';
        
        $this->load->view('client_view.php', $data);
    }
    
    public function request()
    {
        $data['title'] = 'xmlrpc';
        $data['heading'] = 'xmlrpc server response';

        $server_url = site_url('server');

        $this->xmlrpc->server($server_url, 80);
        $this->xmlrpc->method($this->uri->segment(3));
        
        $request = array(
                              array(
                                 array('request' => 'login'),
                                 'struct'),
                              array(
                                 array('username' => 'newuser',
                                       'password' => sha1('123123')),
                                 'struct'));
                
        $this->xmlrpc->request($request);
        
        if(! $this->xmlrpc->send_request())
        {
            echo $data['response'] = $this->xmlrpc->display_error();
        }
        else
        {
            echo $data['response'] = $this->xmlrpc->display_response();
        }
    }
}

CONTROLLER: server.php

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.user_login');

        $this->xmlrpcs->initialize($config);
        $this->xmlrpcs->serve();
    }

    public function user_login($request)
    {
        $uid = 'newuser';
        $psw = sha1('123123');
        
        $parameters = $request->output_parameters();
        
        if($parameters['1']['username'] == $uid && $parameters['1']['password'] == $psw)
        {
            $response = array(
                                       array('REQUEST' => array($parameters['0']['request'], 'string'),
                                             'RESPONSE'=> array('successful', 'string')),
                            'struct');
        
            return $this->xmlrpc->send_response($response);
        }
        else
        {
            return $this->xmlrpc->send_error_message('100', 'fail');
        }
    }
}

RESPONSE:

Code:
---DATA---
HTTP/1.1 200 OK
Date: Tue, 17 May 2011 15:42:04 GMT
Server: Apache/2.2.11 (Win32) PHP/5.3.0
X-Powered-By: PHP/5.3.0
Content-Length: 314
Connection: close
Content-Type: text/xml



<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>REQUEST</name>
<value>
<string>login</string>
</value>
</member>
<member>
<name>RESPONSE</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.

El Forum

[eluser]LastRoseStudios[/eluser]
in your request try
Code:
array(
    array(
        'request' => array('login','string'),
        'username' => array('newuser','string'),
        'password' => array(sha1('123123'),'string')
    ),'struct'
);