CodeIgniter Forums
How to make xmlrpc server work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to make xmlrpc server work (/showthread.php?tid=64590)



How to make xmlrpc server work - littlefeather - 03-08-2016

I have followed (cut and paste) your xmlrpx example form the user guide. I would expect hat the end result would be that the example would work but no it failes. I have tried every possible example i could find online and nothing works

Here is my xmlrpc_server controller


Code:
[code]<?php

class Xmlrpc_server extends CI_Controller {

        public function index()
        {
                $this->load->library('xmlrpc');
                $this->load->library('xmlrpcs');

                $config['functions']['Greetings'] = array('function' => 'Xmlrpc_server.process');
$config['object'] = $this;
                $this->xmlrpcs->initialize($config);
                $this->xmlrpcs->serve();
        }


        public function process($request)
        {
                $parameters = $request->output_parameters();

                $response = array(
                        array(
                                'you_said'  => $parameters[0],
                                'i_respond' => 'Not bad at all.'
                        ),
                        'struct'
                );

                return $this->xmlrpc->send_response($response);
        }
}

here is my xmlrpc client controller
Code:
<?php

class Xmlrpc_client extends CI_Controller {

        public function index()
        {
                $this->load->helper('url');
                $server_url = site_url('xmlrpc_server/index');

                $this->load->library('xmlrpc');

                $this->xmlrpc->server($server_url, 80);
                $this->xmlrpc->method('Greetings');

                $request = array('How is it going?');
                $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>';
                }
        }
}
the error i am getting is totaly useless

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.

How do i make this work waht is wrong with my files?


[/code]


RE: How to make xmlrpc server work - ciadmin - 03-08-2016

If you turn xmlrpc debugging on, you can see if a server exception is being returned or if the return "xml" starts with a space instead of the expected XML signature. The latter can happen if you have closing PHP tags with trailing whitespace.
I also notice that you are using the url helper ... have you set the base_url in your config.php?


RE: How to make xmlrpc server work - skunkbad - 03-08-2016

This works for me:

Client:


PHP Code:
<?php if( ! defined('BASEPATH') ) exit('No direct script access allowed');

class 
Xmlrpc_client extends CI_Controller{
    
    public 
function __construct()
    {
        parent::__construct();
    }

    // -----------------------------------------------------------------------

    /**
     * undocumented method
     */
    public function index()
    {
        $this->load->helper('url');
        $server_url site_url('xmlrpc_server'); /* I changed this */

        $this->load->library('xmlrpc');

        $this->xmlrpc->server($server_url80);
        $this->xmlrpc->method('Greetings');

        $request = array('How is it going?');
        $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>';
        }
    }
    
    
// -----------------------------------------------------------------------
}

/* End of file Xmlrpc_client.php */
/* Location: /application/controllers/Xmlrpc_client.php */ 



Server:


PHP Code:
<?php if( ! defined('BASEPATH') ) exit('No direct script access allowed');

class 
Xmlrpc_server extends CI_Controller{
    
    public 
function __construct()
    {
        parent::__construct();
    }

    // -----------------------------------------------------------------------

    /**
     * undocumented method
     */
    public function index()
    {
        $this->load->library('xmlrpc');
        $this->load->library('xmlrpcs');

        $config['functions']['Greetings'] = array(
            'function' => 'Xmlrpc_server.process'
        );

        $config['object'] = $this;
        $this->xmlrpcs->initialize($config);
        $this->xmlrpcs->serve();
    }

    /**
     * undocumented method
     */
    public function process$request )
    {
        $parameters $request->output_parameters();

        $response = array(
            array(
                'you_said'  => $parameters[0],
                'i_respond' => 'Not bad at all.'
            ),
            'struct'
        );

        return $this->xmlrpc->send_response$response );
    }
    
    
// -----------------------------------------------------------------------
}

/* End of file Xmlrpc_server.php */
/* Location: /application/controllers/Xmlrpc_server.php */ 



RE: How to make xmlrpc server work - littlefeather - 03-08-2016

(03-08-2016, 05:31 PM)skunkbad Wrote: This works for me:

Client:

Now I'm getting error xml. Error not well formed invalid token at line 1
PHP Code:
<?php if( ! defined('BASEPATH') ) exit('No direct script access allowed');

class 
Xmlrpc_client extends CI_Controller{
    
    public 
function __construct()
    {
        parent::__construct();
    }

    // -----------------------------------------------------------------------

    /**
     * undocumented method
     */
    public function index()
    {
        $this->load->helper('url');
        $server_url site_url('xmlrpc_server'); /* I changed this */

        $this->load->library('xmlrpc');

        $this->xmlrpc->server($server_url80);
        $this->xmlrpc->method('Greetings');

        $request = array('How is it going?');
        $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>';
        }
    }
    
    
// -----------------------------------------------------------------------
}

/* End of file Xmlrpc_client.php */
/* Location: /application/controllers/Xmlrpc_client.php */ 



Server:


PHP Code:
<?php if( ! defined('BASEPATH') ) exit('No direct script access allowed');

class 
Xmlrpc_server extends CI_Controller{
    
    public 
function __construct()
    {
        parent::__construct();
    }

    // -----------------------------------------------------------------------

    /**
     * undocumented method
     */
    public function index()
    {
        $this->load->library('xmlrpc');
        $this->load->library('xmlrpcs');

        $config['functions']['Greetings'] = array(
            'function' => 'Xmlrpc_server.process'
        );

        $config['object'] = $this;
        $this->xmlrpcs->initialize($config);
        $this->xmlrpcs->serve();
    }

    /**
     * undocumented method
     */
    public function process$request )
    {
        $parameters $request->output_parameters();

        $response = array(
            array(
                'you_said'  => $parameters[0],
                'i_respond' => 'Not bad at all.'
            ),
            'struct'
        );

        return $this->xmlrpc->send_response$response );
    }
    
    
// -----------------------------------------------------------------------
}

/* End of file Xmlrpc_server.php */
/* Location: /application/controllers/Xmlrpc_server.php */ 



RE: How to make xmlrpc server work - ciadmin - 03-08-2016

Turn xmlrpc debugging on, and show the result. It *really* sounds like your xmlrpc server is returning "xml" that starts with a space or some other invalid character. The latter can happen if you have closing PHP tags with trailing whitespace.


RE: How to make xmlrpc server work - skunkbad - 03-09-2016

If you used my code as-is, and got that error message, then I don't know what to tell you.

Just curious if you really must use XML? It's way easier to create a client/server for JSON. On the client side, all you do is create an array and json_encode it, then echo the encoded string. On the server side all you do is json_decode the request and you're done.


RE: How to make xmlrpc server work - littlefeather - 03-09-2016

Yes i have to use xml as i am making a web interface or a program that only uses xmlrpc
hear is the xml debug output

http://pastebin.com/AYRHaVBW


RE: How to make xmlrpc server work - skunkbad - 03-09-2016

Any chance your files are encode UTF-8 with BOM? If so, try getting rid of the BOM.


RE: How to make xmlrpc server work - littlefeather - 03-09-2016

(03-09-2016, 11:16 AM)skunkbad Wrote: Any chance your files are encode UTF-8 with BOM? If so, try getting rid of the BOM.

How to do that or how do i find out if it is bom?


[Solved] RE: How to make xmlrpc server work - littlefeather - 03-09-2016

I eneded up ownloading the lates CI and overwrote system folder now xmlrpc is working.